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:

/basket.live_shipping_service.list.json

/basket.live_shipping_service.create.json

/basket.live_shipping_service.delete.json

It is possible to view logs of "Live Shipping Service" requests for each added store through your dashboard.



How it works?

Create new shipping service on the store

/basket.live_shipping_service.create.json

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:

  1. Create array of headers, let the header name be its key, its value - the header value string.
    Sort the headers by the name.
  2. Create the string for signature, that is made of headers.For that, encode the array of headers in JSON and concatenate from request body.
  3. Calculate sha256 signature in binary format by using store key as a signing key.
  4. Convert the binary signature to base64.

Php example:

expand source


Test request example(from API2Cart)



expand source

Once you get test request, your endpoint have to respond in JSON format

The response will differ for different shopping carts

For instance, your callback response structure for Shopify will look like the following:


expand source

For WooCommerce the response structure will look like that:

expand source

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

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

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.