Documentation
Feedback
Guides
API Reference

Guides
Integration Guides
Headless commerceHeadless cart and checkout
Headless cart and checkout

This guide explains how to implement a shopping cart and manage the checkout process in a headless ecommerce store, using the Checkout API to handle all interactions through API requests, without a traditional user interface.

A headless store handles all ecommerce integration without a traditional user interface, relying solely on API requests. In this guide, you will learn how to create a shopping cart and manage the checkout flow using features from the Checkout API in your headless store.

New fields can be added in the Checkout API payload without previous warning.

Shopping cart

In the Checkout API, the VTEX shopping cart information is organized using the orderForm, an object containing all information relevant to the purchase, from the products to shipping and payment information, among others.

The orderForm is a complex data structure with many customization possibilities. The essential section for placing an order is divided into items and attachments.

For a customer to make a purchase, the store must have a shopping cart that contains an orderForm for them. When you use the Get current or create a new cart endpoint, you get an orderFormId in the response.

If your headless storefront is not browser-based (e.g., native app), it is important that you save the orderFormId and use it to manage the cart's information with the requests above. Otherwise, VTEX cookies will automatically manage this information in the customer's browser.

Cart items

In the orderForm, product information is stored inside items, where each object corresponds to a SKU contained in the cart. Below is a basic example of a shopping cart containing two units of SKU 123, to be fulfilled by seller 1, at a price of $100.00 per unit.

Request

_10
"items": [
_10
{
_10
"id": "123",
_10
"quantity": 2,
_10
"seller": "1",
_10
"price": 10000
_10
}
_10
]

The information above is sufficient to place an order, but there are other possible fields for shopping cart items, many of which are populated by VTEX modules.

To learn how to add products to a shopping cart, read the guide Add cart items.

If the customer leaves the store, make sure you keep the orderFormId so you can retrieve their previously abandoned cart with the Get cart information by ID endpoint.

Cart attachments

Shopping cart attachments are orderForm objects containing order information related to the client profile, shipping address and delivery option, marketing data, payment data, and merchant context data. Check a basic example of a cart attachments.

Request

_41
{
_41
"userProfileId": "fb542e51-5488-4c34-8d17-ed8fcf597a94",
_41
"profileProvider": "VTEX",
_41
"availableAccounts": [],
_41
"availableAddresses": [
_41
{
_41
"addressType": "residential",
_41
"receiverName": "Clark Kent",
_41
"addressId": "666c2e830bd9474ab6f6cc53fb6dd2d2",
_41
"isDisposable": false,
_41
"postalCode": "12345-000",
_41
"city": "Metropolis",
_41
"state": "NY",
_41
"country": "USA",
_41
"street": "My street",
_41
"number": "123",
_41
"neighborhood": "My neighborhood",
_41
"complement": null,
_41
"reference": null,
_41
"geoCoordinates": [-47.924747467041016, -15.832582473754883]
_41
}
_41
],
_41
"userProfile": {
_41
"email": "clark.kent@example.com",
_41
"firstName": "Clark",
_41
"lastName": "Kent",
_41
"document": "12345678900",
_41
"documentType": "cpf",
_41
"phone": "+556199999999",
_41
"corporateName": null,
_41
"tradeName": null,
_41
"corporateDocument": null,
_41
"stateInscription": null,
_41
"corporatePhone": null,
_41
"isCorporate": false,
_41
"profileCompleteOnLoading": null,
_41
"profileErrorOnLoading": null,
_41
"customerClass": null
_41
},
_41
"isComplete": true
_41
}

Some attachments may contain arrays of objects, where each object corresponds to an item in the items array.

Place order

There are two ways of placing orders with the Checkout API:

  • Place new order: Manage shopping cart information in your frontend and then use one API request to send all order information to VTEX.
  • Place order from existing cart: Manage shopping cart information in the VTEX platform throughout the shopping experience, then place an order from that data using just the cart ID.

The place new order method increases the complexity of your application since you must manage all shopping cart data to correctly assemble the orderForm. Additionally, placing a new order does not send shopping cart information to VTEX until the customers complete their purchase.

The place order from existing cart method is recommended in most cases. Use place new order if your operation has specific requirements, such as limiting the number of HTTP requests sent from your storefront.

Place new order

To place a new order without any shopping cart data previously stored on the VTEX platform, use the Place order endpoint.

For a tutorial of this method, check the guide Create a regular order from an existing cart or follow the steps in the Create a regular order using the Checkout API.

Place order from existing cart

You can also place an order from an existing cart, which already has an orderForm structure and a shopping cart ID. To do so, use the Place order from an existing cart endpoint or follow the steps in the Create a regular order from an existing cart guide.

This endpoint may be used to perform tasks such as adding products to a cart or linking shipping information to the order.

Order privacy

During the process of placing the order, merchants need to account for the security and privacy of customer information throughout checkout.

When a new cart is created, a new cookie named CheckoutOrderFormOwnership is sent empty alongside the existing checkout.vtex.com cookie, which contains the cart's orderFormId. This mechanism ensures that only the customer who created the cart has unrestricted access to their personal information.

You need to make requests with the client data to set CheckoutOrderFormOwnership to a value. Without this cookie, the returned order form will have masked personal data such as clientProfileData and shippingData.

Please contact VTEX support to enable this feature in your store. This feature is not available to stores using FastStore.

Add client profile data

Once you created a new cart, use the Get current or create a new cart endpoint to retrieve the created orderForm, as in the example.

Request
Response-Get-current-or-create-a-new-cart

_109
{
_109
"orderFormId": "9ceee0fde6db489fbc682a0e2ab13a86",
_109
"salesChannel": "1",
_109
"loggedIn": false,
_109
"isCheckedIn": false,
_109
"storeId": "1",
_109
"checkedInPickupPointId": "21",
_109
"allowManualPrice": false,
_109
"canEditData": true,
_109
"userProfileId": "fb542e51-5488-4c34-8d17-ed8fcf597a94",
_109
"userType": "User type",
_109
"ignoreProfileData": false,
_109
"value": 0,
_109
"messages": [],
_109
"items": [],
_109
"selectableGifts": [],
_109
"totalizers": [],
_109
"shippingData": null,
_109
"clientProfileData": {
_109
"email": "clark.kent@examplemail.com",
_109
"firstName": "Clark",
_109
"lastName": "Kent",
_109
"document": "12345678900",
_109
"documentType": "cpf",
_109
"phone": "+5500123456789",
_109
"corporateName": "company-name",
_109
"tradeName": "trade-name",
_109
"corporateDocument": "12345678000100",
_109
"stateInscription": "12345678",
_109
"corporatePhone": "551100988887777",
_109
"isCorporate": false,
_109
"profileCompleteOnLoading": false,
_109
"profileErrorOnLoading": false,
_109
"customerClass": null
_109
},
_109
"paymentData": {
_109
"installmentOptions": [],
_109
"paymentSystems": [],
_109
"payments": [
_109
{
_109
"paymentSystem": 6,
_109
"bin": null,
_109
"accountId": "12",
_109
"tokenId": null,
_109
"value": 34390,
_109
"referenceValue": 34390,
_109
"giftCardRedemptionCode": null,
_109
"giftCardProvider": null,
_109
"giftCardId": null
_109
}
_109
],
_109
"giftCards": [],
_109
"giftCardMessages": [],
_109
"availableAccounts": [],
_109
"availableTokens": []
_109
},
_109
"marketingData": null,
_109
"sellers": [],
_109
"clientPreferencesData": {
_109
"locale": "pt-BR",
_109
"optinNewsLetter": null
_109
},
_109
"commercialConditionData": null,
_109
"storePreferencesData": {
_109
"countryCode": "BRA",
_109
"saveUserData": true,
_109
"timeZone": "E. South America Standard Time",
_109
"currencyCode": "BRL",
_109
"currencyLocale": 1046,
_109
"currencySymbol": "R$",
_109
"currencyFormatInfo": {
_109
"currencyDecimalDigits": 2,
_109
"currencyDecimalSeparator": ",",
_109
"currencyGroupSeparator": ".",
_109
"currencyGroupSize": 3,
_109
"startsWithCurrencySymbol": true
_109
}
_109
},
_109
"giftRegistryData": null,
_109
"openTextField": null,
_109
"invoiceData": null,
_109
"customData": null,
_109
"itemMetadata": {
_109
"items": [
_109
{
_109
"id": "1",
_109
"seller": "1",
_109
"name": "Purina Friskies Wet Cat Food Gravy Pate",
_109
"skuName": "Purina Friskies Wet Cat Food Gravy Pate",
_109
"productId": "1",
_109
"refId": "0001",
_109
"ean": "123456789",
_109
"imageUrl": "http://lojadobreno.vteximg.com.br/arquivos/ids/155450-55-55/Racao-Royal-Canin-Feline-Urinary-SO.jpg?v=637139444438700000",
_109
"detailUrl": "/racao-royal-canin-feline-urinary/p",
_109
"assemblyOptions": []
_109
}
_109
]
_109
},
_109
"hooksData": null,
_109
"ratesAndBenefitsData": {
_109
"rateAndBenefitsIdentifiers": [],
_109
"teaser": []
_109
},
_109
"subscriptionData": null,
_109
"itemsOrdination": {
_109
"criteria": "NAME",
_109
"ascending": true
_109
}
_109
}

Once you have the orderForm, you must add the client data to it. To do so, send the profile data in the Add client profile endpoint request, as in the example.

Request
Response-Get-current-or-create-a-new-cart
Request-Add-client-profile

_14
{
_14
"email": "customer@examplemail.com",
_14
"firstName": "first-name",
_14
"lastName": "last-name",
_14
"documentType": "cpf",
_14
"document": "123456789",
_14
"phone": "+55110988887777",
_14
"corporateName": "company-name",
_14
"tradeName": "trade-name",
_14
"corporateDocument": "12345678000100",
_14
"stateInscription": "12345678",
_14
"corporatePhone": "+551100988887777",
_14
"isCorporate": false
_14
}

For more information about this endpoint, check the guide Adding customer profile information to the cart.

After making this request, the CheckoutOrderFormOwnership cookie will be set as a string with encrypted values of the client profile data.

Add address data

Once the client data has been added, it is also important to add the customer address data to the orderForm. This data includes all information about the delivery of the order to the customer. To do so, use the Add shipping address and select delivery option endpoint.

Request
Response-Get-current-or-create-a-new-cart
Request-Add-client-profile

_27
{
_27
"clearAddressIfPostalCodeNotFound": false,
_27
"selectedAddresses": [
_27
{
_27
"addressType": "residential",
_27
"receiverName": "receiver name",
_27
"addressId": "c3701fc4c61b4d1b91f67e81415db44d",
_27
"postalCode": "12345-000",
_27
"city": "Rio de Janeiro",
_27
"state": "RJ",
_27
"country": "BRA",
_27
"street": "Praia de Botafogo",
_27
"number": "300",
_27
"neighborhood": "Botafogo",
_27
"complement": "3rd floor",
_27
"reference": "Grey building",
_27
"geoCoordinates": [-47.924747467041016, -15.832582473754883]
_27
}
_27
],
_27
"logisticsInfo": [
_27
{
_27
"itemIndex": 0,
_27
"selectedDeliveryChannel": "delivery",
_27
"selectedSla": "normal"
_27
}
_27
]
_27
}

For more information about this endpoint, check the Adding shipping address and delivery options to the cart guide.

When making this request, the CheckoutOrderFormOwnership cookie is updated with this new information.

Unmask orderForm

VTEX Personal Identifiable Information (PII) data is masked by default. This means that when you access a shopper's order history in the VTEX Admin panel or when you request their profile information via API, for example, any PII information returned will be masked.

After adding the client profile data and address data, you can access the previously masked information. Use the Get current or create a new cart endpoint again, but include the latest CheckoutOrderFormOwnership cookie value in the request.

With the correct ownership cookie, both client profile data and address data are unmasked, providing the full details.

Complete order

After placing an order using either of the methods presented above, you will receive an orderId and transactionId in the response body, along with some login values. Your integration must use this information to complete the purchase process within five minutes. This involves sending payment information and then requesting order processing.

Failing to perform these steps within five minutes will cause the order to be automatically canceled and tagged as incomplete.

Send payment information

To send the payment information to VTEX, use one of these endpoints:

The request body used in this step is based on the order's paymentData attachment. You can get this data from the response of the Get client profile by email, as in the example.

Request
Response-Get-current-or-create-a-new-cart
Request-Add-client-profile

_28
"paymentData":{
_28
"updateStatus":"updated",
_28
"installmentOptions":[
_28
{
_28
"paymentSystem":2,
_28
"bin":null"paymentName":null"paymentGroupName":null"value":65780,
_28
"installments":[
_28
{
_28
"count":1,
_28
"hasInterestRate":false,
_28
"interestRate":0,
_28
"value":65780,
_28
"total":65780,
_28
"sellerMerchantInstallments":[
_28
{
_28
"id":"MYSHOP",
_28
"count":1,
_28
"hasInterestRate":false,
_28
"interestRate":0,
_28
"value":65780,
_28
"total":65780
_28
}
_28
]
_28
}
_28
]
_28
}
_28
]
_28
}

Learn more about these endpoints:

Make sure that all value-related fields match the information sent when placing the order to create a successful request.

Retrieving saved credit cards

In the payment section at checkout, we recommend retrieving the saved credit card information from the customer profile. This can ease the checkout process as the customer would only need to select the chosen credit card and input the CVV (Card Verification Value). This process will only display the last four numbers of a credit card to the customer, making it a secure interaction with the client data.

To check if the customer has any saved cards, use the Get client profile by email endpoint. This endpoint returns the available cards. The card information is displayed in the availableAccounts array, as shown in the examples.

Request
Response-Get-current-or-create-a-new-cart
Request-Add-client-profile
Response-for-customer-with-available-cards

_21
{
_21
"userProfileId": "f072eafc-53a4-4aa7-9e14-6b266f918e77",
_21
"profileProvider": "PROFILE PROVIDER DESCRIPTION",
_21
"availableAccounts": [
_21
{
_21
"accountId": "AD6ADBF4359F4B3EBCC4A61ADD176BBE",
_21
"paymentSystem": "2",
_21
"paymentSystemName": "Visa",
_21
"cardNumber": "************7127",
_21
"bin": "415275",
_21
"availableAddresses": [
_21
"XJC",
_21
"6356888228140",
_21
"SPT",
_21
"XPJ"
_21
],
_21
"isExpired": null
_21
}
_21
],
_21
...
_21
}

Response-for-customer-with-no-available-cards

_10
{
_10
"userProfileId": "f072eafc-53a4-4aa7-9e14-6b266f918e77",
_10
"profileProvider": "PROFILE PROVIDER DESCRIPTION",
_10
"availableAccounts": [],
_10
...
_10
}

You can enable a checkbox that allows the customer to choose if they want to save the credit card information or not. To learn how to enable it, read the guide Enable the Save user data opt-in.

Cart items

In the orderForm, product information is stored inside items, where each object corresponds to a SKU contained in the cart. Below is a basic example of a shopping cart containing two units of SKU 123, to be fulfilled by seller 1, at a price of $100.00 per unit.

The information above is sufficient to place an order, but there are other possible fields for shopping cart items, many of which are populated by VTEX modules.

To learn how to add products to a shopping cart, read the guide Add cart items.

If the customer leaves the store, make sure you keep the orderFormId so you can retrieve their previously abandoned cart with the Get cart information by ID endpoint.

Cart attachments

Shopping cart attachments are orderForm objects containing order information related to the client profile, shipping address and delivery option, marketing data, payment data, and merchant context data. Check a basic example of a cart attachments.

Some attachments may contain arrays of objects, where each object corresponds to an item in the items array.

Place order

There are two ways of placing orders with the Checkout API:

  • Place new order: Manage shopping cart information in your frontend and then use one API request to send all order information to VTEX.
  • Place order from existing cart: Manage shopping cart information in the VTEX platform throughout the shopping experience, then place an order from that data using just the cart ID.

The place new order method increases the complexity of your application since you must manage all shopping cart data to correctly assemble the orderForm. Additionally, placing a new order does not send shopping cart information to VTEX until the customers complete their purchase.

The place order from existing cart method is recommended in most cases. Use place new order if your operation has specific requirements, such as limiting the number of HTTP requests sent from your storefront.

Place new order

To place a new order without any shopping cart data previously stored on the VTEX platform, use the Place order endpoint.

For a tutorial of this method, check the guide Create a regular order from an existing cart or follow the steps in the Create a regular order using the Checkout API.

Place order from existing cart

You can also place an order from an existing cart, which already has an orderForm structure and a shopping cart ID. To do so, use the Place order from an existing cart endpoint or follow the steps in the Create a regular order from an existing cart guide.

This endpoint may be used to perform tasks such as adding products to a cart or linking shipping information to the order.

Order privacy

During the process of placing the order, merchants need to account for the security and privacy of customer information throughout checkout.

When a new cart is created, a new cookie named CheckoutOrderFormOwnership is sent empty alongside the existing checkout.vtex.com cookie, which contains the cart's orderFormId. This mechanism ensures that only the customer who created the cart has unrestricted access to their personal information.

You need to make requests with the client data to set CheckoutOrderFormOwnership to a value. Without this cookie, the returned order form will have masked personal data such as clientProfileData and shippingData.

Please contact VTEX support to enable this feature in your store. This feature is not available to stores using FastStore.

Add client profile data

Once you created a new cart, use the Get current or create a new cart endpoint to retrieve the created orderForm, as in the example.

Once you have the orderForm, you must add the client data to it. To do so, send the profile data in the Add client profile endpoint request, as in the example.

For more information about this endpoint, check the guide Adding customer profile information to the cart.

After making this request, the CheckoutOrderFormOwnership cookie will be set as a string with encrypted values of the client profile data.

Add address data

Once the client data has been added, it is also important to add the customer address data to the orderForm. This data includes all information about the delivery of the order to the customer. To do so, use the Add shipping address and select delivery option endpoint.

For more information about this endpoint, check the Adding shipping address and delivery options to the cart guide.

When making this request, the CheckoutOrderFormOwnership cookie is updated with this new information.

Unmask orderForm

VTEX Personal Identifiable Information (PII) data is masked by default. This means that when you access a shopper's order history in the VTEX Admin panel or when you request their profile information via API, for example, any PII information returned will be masked.

After adding the client profile data and address data, you can access the previously masked information. Use the Get current or create a new cart endpoint again, but include the latest CheckoutOrderFormOwnership cookie value in the request.

With the correct ownership cookie, both client profile data and address data are unmasked, providing the full details.

Complete order

After placing an order using either of the methods presented above, you will receive an orderId and transactionId in the response body, along with some login values. Your integration must use this information to complete the purchase process within five minutes. This involves sending payment information and then requesting order processing.

Failing to perform these steps within five minutes will cause the order to be automatically canceled and tagged as incomplete.

Send payment information

To send the payment information to VTEX, use one of these endpoints:

The request body used in this step is based on the order's paymentData attachment. You can get this data from the response of the Get client profile by email, as in the example.

Learn more about these endpoints:

Make sure that all value-related fields match the information sent when placing the order to create a successful request.

Retrieving saved credit cards

In the payment section at checkout, we recommend retrieving the saved credit card information from the customer profile. This can ease the checkout process as the customer would only need to select the chosen credit card and input the CVV (Card Verification Value). This process will only display the last four numbers of a credit card to the customer, making it a secure interaction with the client data.

To check if the customer has any saved cards, use the Get client profile by email endpoint. This endpoint returns the available cards. The card information is displayed in the availableAccounts array, as shown in the examples.

You can enable a checkbox that allows the customer to choose if they want to save the credit card information or not. To learn how to enable it, read the guide Enable the Save user data opt-in.

Request

_10
"items": [
_10
{
_10
"id": "123",
_10
"quantity": 2,
_10
"seller": "1",
_10
"price": 10000
_10
}
_10
]

Process order

Lastly, you must request order processing by using the Process order endpoint after the order's payment is approved. If the payment has not been approved yet, it will return a status code 500 error.

Keep in mind that this process uses the gateway connectors configured in your VTEX environment. Be careful when using it to avoid any unwanted charges or unexpected payment denials.

Verify order status

Once you have successfully placed an order, sent payment information, and requested order processing, you will be able to see the order in the Order management module in VTEX Admin.

You can also use the Get order and List orders endpoints for this purpose. Another way to check the order updates is by integrating Feed v3 and Hook with your store.

Checkout interface

When a customer goes to your store checkout, your frontend implementation must handle several tasks. Follow the sections below to implement these tasks effectively.

Order details

Order details provided by customers at checkout, such as profile information or shipping address, are attachments of the shopping cart.

You must handle this information based on the order placement method you choose. Refer to the corresponding section for detailed instructions:

Address autofill

Implement an address autofill feature using the following endpoint:

Pickup points

Shipping information is added to the order as orderForm attachments. To allow customers to choose nearby pickup points, use the following endpoint:

reCAPTCHA integration does not work in Headless checkout. It only works with stores using Checkout v6.

Learn more

Check these other guides to learn more about building a headless shopping experience using VTEX:

Contributors
2
Photo of the contributor
Photo of the contributor
+ 2 contributors
Was this helpful?
Yes
No
Suggest Edits (GitHub)
Contributors
2
Photo of the contributor
Photo of the contributor
+ 2 contributors
On this page