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.
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Book Your Demo Today & Get an Extra 7 Days Added to Your Free Trial!
Discover how API2Cart can ease your eCommerce integrations with a personalized demo. See how seamlessly our solution can connect your software with over 40 eCommerce platforms.
Don't miss out! This is an exclusive one-time offer. Secure your additional trial period by booking your demo now.