External shipping costs
How to manage shipping methods cost via external services
Last updated
How to manage shipping methods cost via external services
Last updated
Sometimes, you can decide not to manage the price of a shipping method within Commerce Layer but use an external service instead. You may want to do that in order to support more dynamic or custom shipment pricing or just leverage an existing service that you want to keep as your system of records.
If you want to use the external shipping cost feature for one (or more) of your shipping methods, fill in the 's external_prices_url
field with your external service endpoint and make sure your service is compliant with the specifications described below.
Set the scheme
attribute to external
if you want the shipping method's price to be provided by your external service, overriding the shipping method's price_amount_cents
you set at creation time. Also, remember to specify the external_prices_url
if you haven't already set it via the dashboard UI when creating the shipping method:
When the external shipping method is associated with a shipment, Commerce Layer triggers a POST
request to the specified external_prices_url
endpoint, sending the shipment payload (including the shipping method) in the request body.
The request payload is a JSON:API-compliant object you can query to perform your own computation. Aside from the target resource — shipments
in this specific case — the associated shipping method is also included as a relationship:
In case the call to your external endpoint goes timeout, responds with an internal server error, or is blocked by the open circuit breaker, the API keeps responding with a 200 OK
status code. The default shipping price is used (if any) and the circuit breaker internal counter (if closed) is incremented.
Your service response (or error) must match the format described in the example below.
The successful response must be a JSON object, returning the shipping method's price computed by the external logic, along with some additional information and metadata:
When you activate external shipping method costs, a shared secret is generated at the market level. We recommend verifying the callback authenticity by signing the payload with that shared secret and comparing the result with the callback signature header.
Callbacks securityFor performance reasons, when for an order the price is not updated with the value calculated externally which is fetched only when the shipping method is .