Inventory & Products | Products | Costs | Get Product Costs

Getting Product Costs Data

This document outlines the procedure for making API calls to retrieve product costs data from https://easycms.fi/public_api/get_products_costs/.

Important Note

The pid (Product ID) parameter is MANDATORY for this endpoint. You must provide a valid product ID to retrieve cost data.

Product Costs Data Retrieval

Fetch product costs data effectively using the below API call.

Endpoint and Method

  • Endpoint: https://easycms.fi/public_api/get_products_costs/
  • Method: GET or POST

Parameters | Payload

  • TOKEN (api_key): Your unique API key for authentication. How to Create API Credentials.
  • username: Your login username.
  • password: Your login password.
  • account: Your specific account ID.

Required Parameter

  • pid: Product ID (MANDATORY) - The ID of the product to retrieve costs for. Must be an integer.

Pagination Parameters

  • start - Specify the starting point of the row from which to begin fetching product costs (default: 0).
  • limit - Control the number of product costs returned in a single request (default: 50, max: 50).



Call Examples in Different Languages


curl -X POST 'https://easycms.fi/public_api/get_products_costs' \
-H 'Authorization1: TOKEN' \
-d 'username=USERNAME&password=PASSWORD&account=ACCOUNT_ID&pid=12345'

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://easycms.fi/public_api/get_products_costs",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => http_build_query([
    'username' => 'USERNAME', 
    'password' => 'PASSWORD', 
    'account' => 'ACCOUNT_ID',
    'pid' => 12345
  ]),
  CURLOPT_HTTPHEADER => array("Authorization1: TOKEN"),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

import requests
url = "https://easycms.fi/public_api/get_products_costs"
headers = {"Authorization1": "TOKEN"}
payload = {
    'username': 'USERNAME', 
    'password': 'PASSWORD', 
    'account': 'ACCOUNT_ID',
    'pid': 12345
}
response = requests.post(url, headers=headers, data=payload)
print(response.text)

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://easycms.fi/public_api/get_products_costs"))
    .headers("Authorization1", "TOKEN")
    .POST(HttpRequest.BodyPublishers.ofString("username=USERNAME&password=PASSWORD&account=ACCOUNT_ID&pid=12345"))
    .build();
HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

const https = require('https');
const data = new URLSearchParams({ 
  username: 'USERNAME', 
  password: 'PASSWORD', 
  account: 'ACCOUNT_ID',
  pid: 12345
}).toString();
const options = {
  hostname: 'easycms.fi',
  path: '/public_api/get_products_costs',
  method: 'POST',
  headers: {
    'Authorization1': 'TOKEN',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': data.length
  }
};
const req = https.request(options, (res) => {
  let data = '';
  res.on('data', (chunk) => { data += chunk; });
  res.on('end', () => { console.log(data); });
});
req.on('error', (e) => { console.error(e); });
req.write(data);
req.end();

import React, { useEffect, useState } from 'react';
function App() {
  const [productCostsData, setProductCostsData] = useState('');
  useEffect(() => {
    const fetchData = async () => {
      try {
        const response = await fetch('https://easycms.fi/public_api/get_products_costs', {
          method: 'POST',
          headers: {'Authorization1': 'TOKEN', 'Content-Type': 'application/x-www-form-urlencoded'},
          body: new URLSearchParams({
            username: 'USERNAME', 
            password: 'PASSWORD', 
            account: 'ACCOUNT_ID',
            pid: 12345
          }).toString()
        });
        const data = await response.text();
        setProductCostsData(data);
      } catch (error) {
        console.error(error);
      }
    };
    fetchData();
  }, []);
  return (
{productCostsData}
); } export default App;

// Kotlin Example using OkHttp for POST request
import okhttp3.OkHttpClient
import okhttp3.FormBody
import okhttp3.Request

fun main() {
    val client = OkHttpClient()

    val formBody = FormBody.Builder()
        .add("username", "USERNAME")
        .add("password", "PASSWORD")
        .add("account", "ACCOUNT_ID")
        .add("pid", "12345")
        .build()

    val request = Request.Builder()
        .url("https://easycms.fi/public_api/get_products_costs")
        .post(formBody)
        .addHeader("Authorization1", "TOKEN")
        .build()

    client.newCall(request).execute().use { response ->
        if (!response.isSuccessful) throw IOException("Unexpected code $response")
        println(response.body?.string())
    }
}

using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program
{
    static async Task Main()
    {
        var token = "TOKEN";
        var content = new FormUrlEncodedContent(new[]
        {
            new KeyValuePair("username", "USERNAME"),
            new KeyValuePair("password", "PASSWORD"),
            new KeyValuePair("account", "ACCOUNT_ID"),
            new KeyValuePair("pid", "12345")
        });
        using (var httpClient = new HttpClient())
        {
            httpClient.DefaultRequestHeaders.Add("Authorization1", token);
            var response = await httpClient.PostAsync("https://easycms.fi/public_api/get_products_costs", content);
            if (response.IsSuccessStatusCode)
            {
                var responseData = await response.Content.ReadAsStringAsync();
                Console.WriteLine(responseData);
            }
            else
            {
                Console.WriteLine($"Error: {response.StatusCode}");
            }
        }
    }
}




Handling Endpoint Results

When you make a request to the endpoint, you receive a JSON response containing various keys and values. Here's an explanation of the response keys and their meanings:


- `start`: This represents the starting index for the data. In this case, it's set to 0, indicating that the data starts from the first item.

- `limit`: The maximum number of items returned in the response. In this example, the limit is set to 50, meaning that the response will include up to 50 items.

- `count`: The number of items included in the current response. In this case, there is 1 item in the response.

- `total_count`: The total count of items available in the dataset. In this response, there is a total of 1 item available.

    

- `customs_fees`: Customs fees - Import duties and customs costs.
- `transportation_costs`: Transportation costs - Shipping and freight costs.
- `transit_insurance`: Transit insurance - Insurance during transport.
- `handling_fees`: Handling fees - Warehouse handling costs.
- `warehousing`: Warehousing costs - Daily storage costs.
- `handling_labor`: Handling labor costs - Labor costs per day.
- `inventory_write_offs`: Inventory write-offs - Write-offs and damages.
- `shrinkage`: Shrinkage costs - Loss/theft over time.
- `administrative_overheads`: Administrative overheads - Admin costs.
- `utilities`: Utilities costs - Electricity, water, etc.
- `taxes_on_inventory`: Taxes on inventory - Inventory taxes.
- `packaging_costs`: Packaging costs - Packaging materials.
- `marketing_and_promotion`: Marketing and promotion - Marketing allocation.
- `returns_management`: Returns management - Return processing costs.
- `financial_costs`: Financial costs - Interest and financing costs.

These key-value pairs provide comprehensive information about the product costs and can be used for various purposes in your application.
    

{
  "INFO": {
    "start": 0,
    "limit": 50,
    "count": 1,
    "total_count": 1
  },
  "OUTPUT": [
    {
      "customs_fees": 10.50,
      "transportation_costs": 5.00,
      "transit_insurance": 2.25,
      "handling_fees": 1.75,
      "warehousing": 0.50,
      "handling_labor": 0.25,
      "inventory_write_offs": 0.10,
      "shrinkage": 0.05,
      "administrative_overheads": 0.30,
      "utilities": 0.15,
      "taxes_on_inventory": 0.20,
      "packaging_costs": 1.20,
      "marketing_and_promotion": 0.40,
      "returns_management": 0.80,
      "financial_costs": 0.10
    }
  ]
}
      

Error Handling

Here are the possible error messages and their meanings:

Error Code HTTP Status Description
MISSING_PID 400 The pid parameter is required
INVALID_PID 400 The pid must be a valid integer
PRODUCT_NOT_FOUND 404 The product with the specified pid does not exist
NO_COST_DATA 200 The product exists but has no cost data (returns empty OUTPUT)
UN-AUTHORIZED - _user_name_password_is_set_but_wrong_value! 401 Incorrect username or password
this_account_does_not_exist_or_your_credentials_do_not_match_this_account 401 The account doesn't exist or mismatched credentials
UN-AUTHORIZED - header is set but the header value is not correct! 401 Incorrect authorization header value
Maximum query size is 50 rows per query 400 Exceeded maximum limit of 50 rows per query

Error Response Example

{
  "status": "error",
  "error_code": "MISSING_PID",
  "message": "The pid parameter is required"
}

Cost Types Explanation

The product costs system tracks various cost components per product unit. Each cost type falls into one of two categories:

One-Time Costs

Costs that are incurred once per unit:

  • customs_fees - Import duties and customs
  • transportation_costs - Shipping and freight
  • transit_insurance - Insurance during transport
  • handling_fees - Warehouse handling
  • inventory_write_offs - Write-offs and damages
  • returns_management - Return processing
  • packaging_costs - Packaging materials

Per-Day Costs

Costs that accumulate over time based on storage duration:

  • warehousing - Daily storage costs
  • handling_labor - Labor costs per day
  • shrinkage - Loss/theft over time
  • administrative_overheads - Admin costs
  • utilities - Electricity, water, etc.
  • taxes_on_inventory - Inventory taxes
  • marketing_and_promotion - Marketing allocation
  • financial_costs - Interest and financing