The shopping cart gathers information on the products the customer chooses while browsing a store, such as prices, shipping costs, payment methods, delivery methods, etc. This data may include item prices, shipping value, payment, and delivery methods, among others.
This guide will describe how to add shipping address and delivery options to the shopping cart via API.
Getting shopping cart information
The first step is to get the orderFormId
of the shopping cart to which you want to add the shipping address and delivery options. For more information, read the Getting cart information by ID guide.
Adding a shipping address to the shopping cart
To add a shipping address to the shopping cart, you need to use the Add shipping address and select delivery option endpoint. In this request, you must send the orderFormId
through the URL address, as in the example below:
https://{accountName}.{environment.com.br}/api/checkout/pub/orderForm/ede846222cd44046ba6c638442c3505a/attachments/shippingData
Additionally, you need to send the request body with the selectedAddresses
array containing the following information:
addressType
: Address type (e.g. residential, pickup point).receiverName
: Name of the person who will receive the order at the address.postalCode
: Postal code number.city
: City of the shipping address.state
: State of the shipping address.country
: Country of the shipping address, indicated by the three-letter ISO code (e.g. BRA, USA).street
: Street of the shipping address.number
: Number of the shipping address.neighborhood
: Neighborhood of the shipping address.complement
: Shipping address additional information (if necessary).reference
: Additional information that might help locate the shipping address more precisely in case of delivery.geoCoordinates
: Longitude and latitude of the shipping address.
After sending the request, the endpoint will return the response body containing the shipping address information in the shopping cart, as in the example below:
_22..._22"shippingData": {_22 "address": {_22 "addressType": "residential",_22 "receiverName": "receiver-name",_22 "addressId": "c1333270f408494c88858ddc8b3de07e",_22 "isDisposable": true,_22 "postalCode": "12345-000",_22 "city": "Rio de Janeiro",_22 "state": "RJ",_22 "country": "BRA",_22 "street": "Praia de Botafogo",_22 "number": "300",_22 "neighborhood": "Botafogo",_22 "complement": "3rd floor",_22 "reference": "Grey building",_22 "geoCoordinates": [_22 -47.924747467041016,_22 -15.832582473754883_22 ]_22 },_22...
️ For more information on each field available in the shopping cart, see the orderForm overview.
Adding a delivery option to the shopping cart
To add a delivery option to the shopping cart, you must add a shipping address (following the previous section), and use the same Add shipping address and select delivery option endpoint. However, you need to send the request body with the logisticsInfo
array containing the following information:
itemIndex
: Item position in the array or cart.selectedDeliveryChannel
: Delivery option selected by the customer (e.g. delivery, pickup-in-point).selectedSla
: The selected SLA (e.g. normal, express).
After sending the request, the endpoint will return the response body containing the delivery option information in the shopping cart, as in the example below:
_19..._19"logisticsInfo": [_19 {_19 "itemIndex": 0,_19 "selectedSla": "normal",_19 "selectedDeliveryChannel": "delivery",_19 "addressId": "954ee939c1274633bfb7a5af4d6c642d",_19 "slas": [],_19 "shipsTo": [_19 "BRA"_19 ],_19 "itemId": "5",_19 "deliveryChannels": [_19 {_19 "id": "delivery"_19 }_19 ]_19 },_19...
Error codes
The following errors may appear as a message in the response body.
400 - Bad Request
- Message error example (code ORD001):
"The CEP (XXXX) field in the shipping attachment is invalid"
: This message indicates that thepostalCode
used in the request does not exist or is incorrect.
_10{_10 "fields": {},_10 "error": {_10 "code": "ORD001",_10 "message": "The CEP (12340) field in the shipping attachment is invalid",_10 "exception": null_10 },_10 "operationId": "37fcbaf6-9245-46b2-8735-f5fb304d1ac2"_10}
- Message error example (code ORD002):
"Invalid order form"
. TheorderFormId
information is not valid.
_10{_10 "fields": {},_10 "error": {_10 "code": "ORD002",_10 "message": "Invalid order form",_10 "exception": null_10 },_10 "operationId": "5d9f54e6-7db4-46d6-bca9-deeb278b8b98"_10}
- Message error example (code ORD015):
"Unable to communicate with seller VTEX- Test International"
: This message indicates that thegeoCoordinates
used in the request do not exist or are incorrect.
_10{_10 "fields": {},_10 "error": {_10 "code": "ORD015",_10 "message": "Unable to communicate with seller VTEX- Test International",_10 "exception": null_10 },_10 "operationId": "37fcbaf6-9245-46b2-8735-f5fb304d1ac2"_10}
- Message error example (code ORD026):
"A communication error with Postal Code Service has occurred"
: This message indicates that thecountry
information used in the request is not in three-letter ISO code format or does not exist.
_10{_10 "fields": {},_10 "error": {_10 "code": "ORD026",_10 "message": "A communication error with Postal Code Service has occurred",_10 "exception": null_10 },_10 "operationId": "37fcbaf6-9245-46b2-8735-f5fb304d1ac2"_10}
- Message error example (code CHK0041):
"Invalid item index"
: This message indicates that theitemIndex
used in the request does not exist or is incorrect.
_10{_10 "fields": {},_10 "error": {_10 "code": "CHK0041",_10 "message": "Invalid item index",_10 "exception": null_10 },_10 "operationId": "5d9f54e6-7db4-46d6-bca9-deeb278b8b98"_10}
404 - Not Found
- Message error example:
"The requested URL was not found on the server"
: Check if the URL is correct.
_10<body>_10 <h1>404 Not Found</h1>_10 <p>The requested URL was not found on this server.</p>_10</body>