Webhooks: shipping
You can use the shipping rates webhook when you want to handle shipping rates calculation by yourself. Snipcart will call your application at the URL specified in your dashboard.
In your dashboard go to Store configurations → Shipping → Webhooks and enter the required endpoint information.
Snipcart will make an HTTP POST
request to the URL specified. The request body will contain all the current order details.
Request
Method POST
Content-Type application/json
Body
{
"eventName": "shippingrates.fetch",
"mode": "Live",
"createdOn": "2015-02-21T14:58:02.6738454Z",
"content": {
"token": "22808196-0eff-4a6e-b136-3e4d628b3cf5",
"creationDate": "2015-02-21T14:58:02.6738454Z",
"modificationDate": "2015-02-21T14:58:02.6738454Z",
"status": "Processed",
"currency": "USD",
"lang": "en",
"paymentMethod": "CreditCard",
"email": "customer@snipcart.com",
"cardHolderName": "Nicolas Cage",
"billingAddressName": "Nicolas Cage",
"billingAddressCompanyName": "Company name",
"billingAddressAddress1": "888 The street",
"billingAddressAddress2": "",
"billingAddressCity": "Quebec",
"billingAddressCountry": "CA",
"billingAddressProvince": "QC",
"billingAddressPostalCode": "G1G 1G1",
"billingAddressPhone": "(888) 888-8888",
"shippingAddressName": "Nicolas Cage",
"shippingAddressCompanyName": "Company name",
"shippingAddressAddress1": "888 The street",
"shippingAddressAddress2": "",
"shippingAddressCity": "Quebec",
"shippingAddressCountry": "CA",
"shippingAddressProvince": "QC",
"shippingAddressPostalCode": "G1G 1G1",
"shippingAddressPhone": "(888) 888-8888",
"shippingAddressSameAsBilling": true,
"finalGrandTotal": 310.00,
"shippingAddressComplete": true,
"creditCardLast4Digits": "4242",
"shippingFees": 10.00,
"shippingMethod": "Livraison",
"items": [{
"uniqueId": "eb4c9dae-e725-4dad-b7ae-a5e48097c831",
"token": "22808196-0eff-4a6e-b136-3e4d628b3cf5",
"id": "1",
"name": "Movie",
"price": 300.00,
"originalPrice": 300.00,
"quantity": 1,
"url": "https://snipcart.com",
"weight": 10.00,
"description": "Something",
"image": "http://placecage.com/50/50",
"customFieldsJson": "[]",
"stackable": true,
"maxQuantity": null,
"totalPrice": 300.0000,
"totalWeight": 10.00,
"shippable": true,
}],
"subtotal": 610.0000,
"totalWeight": 20.00,
"discounts": [],
"willBePaidLater": false
}
}
Response
Snipcart expects to receive a JSON object containing an array of shipping rates.
Success
Response status code must be 2XX
to indicate that the request has been handled successfully.
Required HTTP headers
Key | Value |
---|---|
Content-Type | application/json |
Content
{
"rates": [{
"cost": 10,
"description": "10$ shipping"
}, {
"cost": 20,
"description": "20$ shipping",
"guaranteedDaysToDelivery": 5
},
...
]
}
Error
If you want Snipcart to show an error message to your customers, you can do so by returning us a 2XX
status code with the following JSON object.
{
"errors": [{
"key": "invalid_postal_code",
"message": "The postal code is invalid."
},
...
]
}