Download the guide "How to Integrate with Multiple eCommerce Platforms in Less than a Month" and find more how to connect your B2B SaaS system with various shopping platforms quickly!
The Live Shipping Rates service is currently supported for the following API2Cart's integrations: .
Please note that depending on the platform, the structure of the request and the expected response will be slightly different, as some platforms may support more fields. That is why we strongly recommend that you familiarize yourself with the structure of the callback request and the response we expect using the Swagger-based documentation below.
To manage "Live Shipping Service" you can use the following API methods:
On WooCommerce stores there can be an unlimited amount of services, but on Shopify you can create only one service (Shopify limit).
To create the service you’ll have to specify the name of the service and callback url, that will return us shipping rates. We validate the callback when it is being created by sending test request to it. Test requests contain header X-Shipping-Service-Test-Request: 1.
To check it the request was really sent by API2Cart, compare header signature X-Shipping-Service-Signature
The signature is built based on all headers that start with X-Shipping-Service, except for X-Shipping-Service-Signature.
The algorithm:
Create array of headers, let the header name be its key, its value - the header value string. Sort the headers by the name.
Create the string for signature, that is made of headers.For that, encode the array of headers in JSON and concatenate from request body.
Calculate sha256 signature in binary format by using store key as a signing key.
When we send a certain amount of packages, we expect to get the same amount of packages_rates objects. The property rates can be empty,
which means there can be no rates for a certain package.
If the structure is not valid, we return an error.For example, you will get error when you pass a string in total_cost.
expand source
{
"return_code": 109,
"return_message": "Bad Response. Field \"rates->0->total_cost\" has wrong type. It must be decimal",
"result": {}
}
If the callback returns 404 error code,we will not try again
If the callback returns 200 error code, we will check response validity and then return it to the store in the format that fits the store.
If the store returns 200 error code, butwith empty or incorrect response, we will wait 2 seconds and will try again.
If the callback don’t respond in 15 seconds, we will throw an error and will not try again.
expand source
{
"return_code": 109,
"return_message": "Callback http://www.stores.local/rates.php did not respond within 15 sec",
"result": {}
}
If everything is ok, the new service will be created.
2) As the store requests rates, we unify the request and send it to callback specified when the service was created. Also, we send
X-Shipping-Service-Id
header.
If the response is not valid or the callback didn’t answer, we will log the error and increment error count of the shipping service by 1.If the next request will be successful, the count will be reduced to zero.Soon we will add the functionality that will turn off the service when the error limit is exceeded.
This website uses cookies to improve your user experience. By using this site you agree to these cookies being set. Find out more in our Privacy Policy