Calculate Domestics Cost
Overviewβ
The Calculate Domestic Cost endpoint enables you to check the estimated shipping cost for deliveries within Indonesia. This feature is particularly useful for platforms that integrate with multiple shipping providers, allowing them to present accurate cost options to their users in real time. By using this API, merchants and developers can dynamically calculate shipping fees based on the origin, destination, and courier service preferences.
This endpoint supports domestic couriers integrated with Komerce and is an essential tool for checkout flows and also shipping calculators.
Key Featureβ
-
π¦ Multi-Courier Support
Supports a wide range of domestic couriers integrated with Komerce API. -
π― Precise Cost Calculation
Returns real-time cost estimates based on origin, destination, and package weight/dimensions. -
π Flexible Input
Accepts both exact destination IDs andsubdistrict
level orzip_code
granularity for more accurate pricing. -
π§Ύ Courier Breakdown
Displays available services, estimated costs, and estimated delivery times.
How it Worksβ
- Prepare the Required Data : Youβll need the origin and destination IDs, courier code, and package details such as weight and optional dimensions.
- Receive a detailed response containing available services, cost per service, and estimated delivery time.
- Use the returned data to display cost options at checkout, or calculate total shipping charges for the order.
Request Bodyβ
- cURL
- JavaScript
- PHP
- GoLang
- Node
curl --location 'https://rajaongkir.komerce.id/api/v1/calculate/domestic-cost' \
--header 'key: inputapikey' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'origin={{ origin.id }}' \
--data-urlencode 'destination={{ destination.id }}' \
--data-urlencode 'weight={{ weight.grams }}' \
--data-urlencode 'courier={{ courier.code }}' \
--data-urlencode 'price={{ lowest/highest }}'
const myHeaders = new Headers();
myHeaders.append("key", "inputapikey");
myHeaders.append("Content-Type", "application/x-www-form-urlencoded");
const urlencoded = new URLSearchParams();
urlencoded.append("origin", "{{ origin.id }}");
urlencoded.append("destination", "{{ destination.id }}");
urlencoded.append("weight", "{{ weight.grams }}");
urlencoded.append("courier", "{{ courier.code }}");
urlencoded.append("price", "{{ lowest/highest }}");
const requestOptions = {
method: "POST",
headers: myHeaders,
body: urlencoded,
redirect: "follow"
};
fetch("https://rajaongkir.komerce.id/api/v1/calculate/domestic-cost", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://rajaongkir.komerce.id/api/v1/calculate/domestic-cost',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => 'origin=%7B%7B%20origin.id%20%7D%7D&destination=%7B%7B%20destination.id%20%7D%7D&weight=%7B%7B%20weight.grams%20%7D%7D&courier=%7B%7B%20courier.code%20%7D%7D&price=%7B%7B%20lowest%2Fhighest%20%7D%7D',
CURLOPT_HTTPHEADER => array(
'key: inputapikey',
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://rajaongkir.komerce.id/api/v1/calculate/domestic-cost"
method := "POST"
payload := strings.NewReader("origin=%7B%7B%20origin.id%20%7D%7D&destination=%7B%7B%20destination.id%20%7D%7D&weight=%7B%7B%20weight.grams%20%7D%7D&courier=%7B%7B%20courier.code%20%7D%7D&price=%7B%7B%20lowest%2Fhighest%20%7D%7D")
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("key", "inputapikey")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
const axios = require('axios');
const qs = require('qs');
let data = qs.stringify({
'origin': '{{ origin.id }}',
'destination': '{{ destination.id }}',
'weight': '{{ weight.grams }}',
'courier': '{{ courier.code }}',
'price': '{{ lowest/highest }}'
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://rajaongkir.komerce.id/api/v1/calculate/domestic-cost',
headers: {
'key': 'inputapikey',
'Content-Type': 'application/x-www-form-urlencoded'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
Query Parameterβ
Headersβ
Key | Type | Description |
---|---|---|
key * | string | this Value contain an secret APIKEY identic for Shipping Cost API |
Body x-www-form-urlencodedβ
Key | Type | Description |
---|---|---|
origin * | int | this Value containt an id during Search Domestics Destinations |
destination * | int | this Value containt an id during Search Domestics Destinations |
weight * | int | this Value containt an a package weight with grams estimated |
courier * | string | this Value contain an Courier Name |
price | boolean | this Value Contain an boolean value, lowest or highest shipping cost |
For each header and parameter that has a *
sign, it is a parameter that must be Required when making a request, otherwise there will be a system error that will warn the user regarding the request made.
Responseβ
Response Structureβ
Key | Value (Description) |
---|---|
meta.message | Response for searching address. |
meta.code | Any response have different code. |
meta.status | Boolean status for checking address. |
data[].name | Information about availability Courier Name |
data[].code | Information about availability Code of Courier |
data[].service | Information about availability Service of Courier |
data[].description | Description about Courier |
data[].cost | Information about Courier Service Cost |
data[].etd | Information about estimated time of courier delivery |
Success Respons for Calculate Domestic Costβ
{
"meta": {
"message": "Success Calculate Domestic Shipping cost",
"code": 200,
"status": "success"
},
"data": [
{
"name": "{{ courier.name }}",
"code": "{{ courier.code }}",
"service": "{{ courier.service }}",
"description": "{{ courier.desc }}",
"cost": {{ shipping.cost }},
"etd": "{{ etd.info }}"
},
]
}
Error Respons for Calculate Domestic Costβ
{
"meta": {
"message": "{{ error.message }}",
"code": {{ error.code }},
"status": "{{ status }}"
},
"data": null
}
Status Codeβ
Code | Status | Description | How to Fix |
---|---|---|---|
200 | Success | ||
400 | Error | Calculate Domestic Shipping Cost not found | This error is unavoidable because the courier may not be able to provide the desired data. |
400 | Error | Missing Params | Make sure the request parameters that are sent match the required parameters. |
422 | Error | Invalid Courier | Make sure the courier code entered is correct according to the courier code guide available for checking. |
Tips to Avoid Errorβ
- π Ensure subdistrict IDs are valid : Use the correct IDs from the Search Destination endpoint.
- βοΈ Use appropriate weight : Weight must be in grams. 1kg = 1000g. Avoid using β0β or negative numbers.
- π Provide valid courier code : Supported courier codes include jne, jnt, sicepat, etc. Make sure the code matches supported ones from the 3PL list.
- π Include Authorization Header : Always attach your Bearer Token using the Authorization: Bearer YOUR_API_KEY format.
- π Handle βno service availableβ gracefully : If no service is returned, inform the user that the route or courier may not be supported.