Documentation
Feedback
Guides

Creating a regular order from an existing cart

Learn how to use VTEX APIs to place a regular order from an existing cart.

This step-by-step guide will walk you through the process of using the Checkout API to create an order from an existing shopping cart. This process is divided into the following steps:

  1. Get cart information: The process begins with retrieving the orderFormId of the current shopping cart via the Get current or create a new cart endpoint.
  2. Place the order: The process continues by placing the order on the VTEX platform via the Place order from an existing cart endpoint.
  3. Handling the order payment and processing: The process ends by sending the necessary payment data to resolve the order payment and processing order details.

Before you begin

Before proceeding any further, ensure that you have a valid appKey and appToken granted with the necessary permissions to access the Checkout and Payments Gateway APIs. For more information, please refer to the Roles article.

Click the steps below to navigate through this article and explore specific topics. Relevant code for each phase or parameter will be highlighted on the right side of the screen.

Step 1 - Getting cart information

Send a GET request to the Get current or create a new cart endpoint to retrieve the orderFormId of the shopping cart you intend to use to create an order.

For more information, access the Get cart information by ID guide.

Shell
Python
Node.js

_10
curl --request get \
_10
--url https://apiexamples.vtexcommercestable.com.br/api/checkout/pub/orderForm \
_10
--header 'Accept: application/json' \
_10
--header 'Content-Type: application/json'

Response

_76
{
_76
"orderFormId": "9ceee0fde6db489fbc682a0e2ab13a86",
_76
"salesChannel": "1",
_76
"loggedIn": false,
_76
"isCheckedIn": false,
_76
"storeId": null,
_76
"checkedInPickupPointId": null,
_76
"allowManualPrice": false,
_76
"canEditData": true,
_76
"userProfileId": null,
_76
"userType": null,
_76
"ignoreProfileData": false,
_76
"value": 0,
_76
"messages": [],
_76
"items": [],
_76
"selectableGifts": [],
_76
"totalizers": [],
_76
"shippingData": null,
_76
"clientProfileData": {
_76
"email": null,
_76
"firstName": null,
_76
"lastName": null,
_76
"document": null,
_76
"documentType": null,
_76
"phone": null,
_76
"corporateName": null,
_76
"tradeName": null,
_76
"corporateDocument": null,
_76
"stateInscription": null,
_76
"corporatePhone": null,
_76
"isCorporate": false,
_76
"profileCompleteOnLoading": null,
_76
"profileErrorOnLoading": null,
_76
"customerClass": null
_76
},
_76
"paymentData": {
_76
"installmentOptions": [],
_76
"paymentSystems": [],
_76
"payments": [],
_76
"giftCards": [],
_76
"giftCardMessages": [],
_76
"availableAccounts": [],
_76
"availableTokens": []
_76
},
_76
"marketingData": null,
_76
"sellers": [],
_76
"clientPreferencesData": {
_76
"locale": "pt-BR",
_76
"optinNewsLetter": null
_76
},
_76
"commercialConditionData": null,
_76
"storePreferencesData": {
_76
"countryCode": "BRA",
_76
"saveUserData": true,
_76
"timeZone": "E. South America Standard Time",
_76
"currencyCode": "BRL",
_76
"currencyLocale": 1046,
_76
"currencySymbol": "R$",
_76
"currencyFormatInfo": {
_76
"currencyDecimalDigits": 2,
_76
"currencyDecimalSeparator": ",",
_76
"currencyGroupSeparator": ".",
_76
"currencyGroupSize": 3,
_76
"startsWithCurrencySymbol": true
_76
}
_76
},
_76
"giftRegistryData": null,
_76
"openTextField": null,
_76
"invoiceData": null,
_76
"customData": null,
_76
"itemMetadata": null,
_76
"hooksData": null,
_76
"ratesAndBenefitsData": null,
_76
"subscriptionData": null,
_76
"itemsOrdination": null
_76
}

Step 2 - Placing the order

Place a new order via the Place order from an existing cart endpoint, providing the following information in the request body:

  • referenceId: orderFormId obtained in the previous step, serving as the unique identifier (ID) of the orderForm associated with the shopping cart from which the order will be created.
  • savePersonalData: set as true if the shopper’s data provided during checkout should be saved for future reference (default is false).
  • optinNewsLetter: set as true if the shopper opted to receive the newsletter (default is false).
  • value: total value of the order without separating cents (e.g., $24.99 is represented by 2499).
  • referenceValue: reference value of the order, without separating cents (e.g., $24.99 is represented by 2499). This is used for calculating interest, if applicable.
  • interestValue: interest rate to be applied, if applicable.

Upon receiving a 201 Created response, the request will provide a response body containing the orderForm with comprehensive details of the newly created regular order. Take note of these pieces of information and proceed to Resolving the order payment.

  • orderId - ID of the order within VTEX’s Order Management System (OMS). You can find the orderId within each object in the orders array.
  • transactionId - ID of the transaction, which can be found within the objects contained in the transactionData.merchantTransactions array.
  • addressId - ID of the customer address. If you plan to use the same address for both shipping and billing, get the addressId from the shippingData.address object.

If you face errors during the request submission, refer to Handling HTTP response errors when placing the order for common error scenarios when placing an order.

Shell
Python
Node.js

_10
curl --request post \
_10
--url 'https://apiexamples.vtexcommercestable.com.br/api/checkout/pub/orderForm/{orderFormId}/transaction' \
_10
--header 'Accept: application/json' \
_10
--header 'Content-Type: application/json' \
_10
--data '{"referenceId":"41a22925298a4ddca95318131a25b000","savePersonalData":false,"optinNewsLetter":false,"value":6800,"referenceValue":6800,"interestValue":0}'

Response

_130
{
_130
"orderForm": null,
_130
"transactionData": {
_130
"merchantTransactions": [
_130
{
_130
"id": "STORE",
_130
"transactionId": "62FEDE228E2144649CF67812C4E5ER79",
_130
"merchantName": "STORE",
_130
"payments": [
_130
{
_130
"paymentSystem": "6",
_130
"bin": null,
_130
"accountId": null,
_130
"value": 15650,
_130
"referenceValue": 15650,
_130
"giftCardRedemptionCode": null,
_130
"giftCardProvider": null,
_130
"giftCardId": null
_130
}
_130
]
_130
}
_130
],
_130
"receiverUri": "https://store.vtexpayments.com.br/split/v976778amgh/payments",
_130
"gatewayCallbackTemplatePath": "/checkout/gatewayCallback/v976778amgh/{messageCode}"
_130
},
_130
"orders": [
_130
{
_130
"orderId": "v976778amgh-01",
_130
"orderGroup": "v976778amgh",
_130
"state": "order-created",
_130
"isCheckedIn": false,
_130
"sellerOrderId": "00-v976778amgh-01",
_130
"storeId": null,
_130
"value": 15650,
_130
"items": [],
_130
"sellers": [],
_130
"totals": [],
_130
"clientProfileData": {
_130
"attachmentId": "clientProfileData",
_130
"email": "marcelo@vtex.com.br",
_130
"firstName": "Marcelo",
_130
"lastName": "Couto",
_130
"document": "71279846675",
_130
"documentType": "cpf",
_130
"phone": "1234567890",
_130
"corporateName": null,
_130
"tradeName": null,
_130
"corporateDocument": null,
_130
"stateInscription": null,
_130
"corporatePhone": null,
_130
"isCorporate": false,
_130
"profileCompleteOnLoading": null,
_130
"profileErrorOnLoading": null
_130
},
_130
"ratesAndBenefitsData": {
_130
"attachmentId": "ratesAndBenefitsData",
_130
"rateAndBenefitsIdentifiers": [],
_130
"teaser": []
_130
},
_130
"shippingData": {
_130
"attachmentId": "shippingData",
_130
"address": {
_130
"addressType": "residential",
_130
"receiverName": "Marcelo",
_130
"addressId": "49ad09e5fba8434a8ff1e0faa4b60ceb",
_130
"postalCode": "28050987",
_130
"city": "Rio de Janeiro",
_130
"state": "RJ",
_130
"country": "BRA",
_130
"street": "Rua da minha casa",
_130
"number": "123",
_130
"neighborhood": "Copacabana",
_130
"complement": "15º andar",
_130
"reference": null,
_130
"geoCoordinates": []
_130
},
_130
"logisticsInfo": [],
_130
"availableAddresses": [
_130
{
_130
"addressType": "residential",
_130
"receiverName": "Marcelo",
_130
"addressId": "49ad09e5fba8434a8ff1e0faa4b60ceb",
_130
"postalCode": "28050642",
_130
"city": "Rio de Janeiro",
_130
"state": "RJ",
_130
"country": "BRA",
_130
"street": "Rua da minha casa",
_130
"number": "123",
_130
"neighborhood": "Copacabana",
_130
"complement": "15º andar",
_130
"reference": null,
_130
"geoCoordinates": []
_130
}
_130
]
_130
},
_130
"paymentData": {
_130
"attachmentId": "paymentData",
_130
"transactionId": "62FEDE228E2144649CF67812C4E5DD87",
_130
"payments": [],
_130
"giftCards": [],
_130
"transactions": [
_130
{
_130
"isActive": true,
_130
"transactionId": "62FEDE228E2144649CF67812C4E5DD87",
_130
"merchantName": "STORE",
_130
"payments": []
_130
}
_130
],
_130
"merchantName": "STORE"
_130
},
_130
"clientPreferencesData": {},
_130
"giftRegistryData": null,
_130
"marketingData": null,
_130
"storePreferencesData": {},
_130
"openTextField": {},
_130
"changeData": null,
_130
"salesChannel": "1",
_130
"followUpEmail": "f1e7309d88dd4633825ce183d52a50a6@ct.vtex.com.br",
_130
"creationDate": "2017-02-16T23:42:43.9605088Z",
_130
"lastChange": "2017-02-16T23:42:47.62285Z",
_130
"timeZoneCreationDate": "2017-02-16T21:42:43.9605088",
_130
"timeZoneLastChange": "2017-02-16T21:42:47.62285",
_130
"isCompleted": false,
_130
"hostName": "ambienteqa",
_130
"merchantName": null,
_130
"userType": "",
_130
"roundingError": 0
_130
}
_130
]
_130
}

Step 3 - Resolving the order payment

Now, we will communicate the necessary payment data to VTEX for the finalization of the order's payment. Note that from now on, you have 5 (five) minutes to complete the payment process.

  • Send a request to the Send payments information public endpoint, considering the following:

    • Use the orderFormId value obtained in the previous step as the orderId query-string parameter.
    • Use the transactionId value obtained in the previous step as a path parameter.
    • Ensure that the request body is based on the paymentData section of your orderForm.
    • In the fields object, use the addressId field to reference an existing address or introduce a new address object for an entirely new address.

If you intend to send saved credit card data, you can use the Send payments with saved credit card endpoint instead.

Shell
Python
Node.js

_10
curl --request post \
_10
--url 'https://{accountName}.vtexpayments.com.br/api/pub/transactions/{transactionId}/payments?orderId={orderId}' \
_10
--header 'Accept: application/json' \
_10
--header 'Content-Type: application/json' \
_10
--header 'X-VTEX-API-AppKey: {appKey}' \
_10
--header 'X-VTEX-API-AppToken: {appToken}' \
_10
--data '[{"paymentSystem":4,"installments":1,"currencyCode":"BRL","value":100,"installmentsInterestRate":0,"installmentsValue":100,"referenceValue":100,"fields":{"holderName":"UserTest","cardNumber":"5378244888889174","validationCode":"231","dueDate":"10/19","document":"8041734561","accountId":"","address":null,"callbackUrl":""},"transaction":{"id":"{{transactionId}}","merchantName":"{{accountName}}"}}]'

Response

_10
200 OK

Step 4 - Processing and validating the order

In this final step, we will process the order.

  • Send a request to the Process order endpoint. If the payment is processed without any issues, the order should be successfully placed. Otherwise, a status 500 error might occur.

Note that this process uses the gateway connectors configured in your VTEX environment. Be careful to prevent any unwanted charges or unexpected payment denials.

Shell
Python
Node.js

_10
curl --request post \
_10
--url 'https://{accountName}.{environment}.com.br/api/checkout/pub/gatewayCallback/{orderGroup}' \
_10
--header 'Accept: application/json' \
_10
--header 'Content-Type: application/json' \
_10
--header 'Cookie: {cookie}' \
_10
--header 'X-VTEX-API-AppKey: {appKey}' \
_10
--header 'X-VTEX-API-AppToken: {appToken}'

Response

_10
200 OK

Step 1 - Getting cart information

Send a GET request to the Get current or create a new cart endpoint to retrieve the orderFormId of the shopping cart you intend to use to create an order.

For more information, access the Get cart information by ID guide.

Step 2 - Placing the order

Place a new order via the Place order from an existing cart endpoint, providing the following information in the request body:

  • referenceId: orderFormId obtained in the previous step, serving as the unique identifier (ID) of the orderForm associated with the shopping cart from which the order will be created.
  • savePersonalData: set as true if the shopper’s data provided during checkout should be saved for future reference (default is false).
  • optinNewsLetter: set as true if the shopper opted to receive the newsletter (default is false).
  • value: total value of the order without separating cents (e.g., $24.99 is represented by 2499).
  • referenceValue: reference value of the order, without separating cents (e.g., $24.99 is represented by 2499). This is used for calculating interest, if applicable.
  • interestValue: interest rate to be applied, if applicable.

Upon receiving a 201 Created response, the request will provide a response body containing the orderForm with comprehensive details of the newly created regular order. Take note of these pieces of information and proceed to Resolving the order payment.

  • orderId - ID of the order within VTEX’s Order Management System (OMS). You can find the orderId within each object in the orders array.
  • transactionId - ID of the transaction, which can be found within the objects contained in the transactionData.merchantTransactions array.
  • addressId - ID of the customer address. If you plan to use the same address for both shipping and billing, get the addressId from the shippingData.address object.

If you face errors during the request submission, refer to Handling HTTP response errors when placing the order for common error scenarios when placing an order.

Step 3 - Resolving the order payment

Now, we will communicate the necessary payment data to VTEX for the finalization of the order's payment. Note that from now on, you have 5 (five) minutes to complete the payment process.

  • Send a request to the Send payments information public endpoint, considering the following:

    • Use the orderFormId value obtained in the previous step as the orderId query-string parameter.
    • Use the transactionId value obtained in the previous step as a path parameter.
    • Ensure that the request body is based on the paymentData section of your orderForm.
    • In the fields object, use the addressId field to reference an existing address or introduce a new address object for an entirely new address.

If you intend to send saved credit card data, you can use the Send payments with saved credit card endpoint instead.

Step 4 - Processing and validating the order

In this final step, we will process the order.

  • Send a request to the Process order endpoint. If the payment is processed without any issues, the order should be successfully placed. Otherwise, a status 500 error might occur.

Note that this process uses the gateway connectors configured in your VTEX environment. Be careful to prevent any unwanted charges or unexpected payment denials.

Shell
Python
Node.js

_10
curl --request get \
_10
--url https://apiexamples.vtexcommercestable.com.br/api/checkout/pub/orderForm \
_10
--header 'Accept: application/json' \
_10
--header 'Content-Type: application/json'

Response

_76
{
_76
"orderFormId": "9ceee0fde6db489fbc682a0e2ab13a86",
_76
"salesChannel": "1",
_76
"loggedIn": false,
_76
"isCheckedIn": false,
_76
"storeId": null,
_76
"checkedInPickupPointId": null,
_76
"allowManualPrice": false,
_76
"canEditData": true,
_76
"userProfileId": null,
_76
"userType": null,
_76
"ignoreProfileData": false,
_76
"value": 0,
_76
"messages": [],
_76
"items": [],
_76
"selectableGifts": [],
_76
"totalizers": [],
_76
"shippingData": null,
_76
"clientProfileData": {
_76
"email": null,
_76
"firstName": null,
_76
"lastName": null,
_76
"document": null,
_76
"documentType": null,
_76
"phone": null,
_76
"corporateName": null,
_76
"tradeName": null,
_76
"corporateDocument": null,
_76
"stateInscription": null,
_76
"corporatePhone": null,
_76
"isCorporate": false,
_76
"profileCompleteOnLoading": null,
_76
"profileErrorOnLoading": null,
_76
"customerClass": null
_76
},
_76
"paymentData": {
_76
"installmentOptions": [],
_76
"paymentSystems": [],
_76
"payments": [],
_76
"giftCards": [],
_76
"giftCardMessages": [],
_76
"availableAccounts": [],
_76
"availableTokens": []
_76
},
_76
"marketingData": null,
_76
"sellers": [],
_76
"clientPreferencesData": {
_76
"locale": "pt-BR",
_76
"optinNewsLetter": null
_76
},
_76
"commercialConditionData": null,
_76
"storePreferencesData": {
_76
"countryCode": "BRA",
_76
"saveUserData": true,
_76
"timeZone": "E. South America Standard Time",
_76
"currencyCode": "BRL",
_76
"currencyLocale": 1046,
_76
"currencySymbol": "R$",
_76
"currencyFormatInfo": {
_76
"currencyDecimalDigits": 2,
_76
"currencyDecimalSeparator": ",",
_76
"currencyGroupSeparator": ".",
_76
"currencyGroupSize": 3,
_76
"startsWithCurrencySymbol": true
_76
}
_76
},
_76
"giftRegistryData": null,
_76
"openTextField": null,
_76
"invoiceData": null,
_76
"customData": null,
_76
"itemMetadata": null,
_76
"hooksData": null,
_76
"ratesAndBenefitsData": null,
_76
"subscriptionData": null,
_76
"itemsOrdination": null
_76
}

Handling HTTP response errors when placing the order

400 - Bad Request (ORD002)

Message error example (code ORD002): "Invalid order form"

  • Issue: The orderFormId information is not valid.
  • Troubleshooting:
    • Verify that the orderFormId is correct.
    • Ensure that the orderFormId corresponds to an existing shopping cart.
Response

_10
{
_10
"fields": {},
_10
"error": {
_10
"code": "ORD002",
_10
"message": "Invalid order form",
_10
"exception": null
_10
},
_10
"operationId": "f01ef909-8b81-4ffd-a91d-82be680d60ff"
_10
}

400 - Bad Request (CHK0016)

Message error example (code CHK0016): "Payment value does not match with reference value"

  • Issue: The value and referenceValue fields have different values even without the use of interest in the payment.
  • Troubleshooting:
    • Confirm that the provided value and referenceValue align correctly.
    • Check if the interest rate is correctly configured.
Response

_10
{
_10
"fields": {},
_10
"error": {
_10
"code": "CHK0016",
_10
"message": "Payment value does not match with reference value",
_10
"exception": null
_10
},
_10
"operationId": "6a080d5f-6911-4469-a661-312e93c23419"
_10
}

404 - Not Found

Message error example: "The requested URL was not found on the server"

  • Issue: The requested URL was not found on the server.
  • Troubleshooting: Check if the endpoint used is correct.
Response

_10
<body>
_10
<h1>404 Not Found</h1>
_10
<p>The requested URL was not found on this server.</p>
_10
</body>

500 - Internal Server Error

Message error example (code ORD005): "The purchase cannot be done without items"

  • Issue: The shopping cart (orderFormId) informed in the request does not have any item, making it impossible to create an order.
  • Troubleshooting:
    • Verify that the specified shopping cart has items.
    • Confirm that the orderFormId corresponds to a valid and non-empty shopping cart.
Response

_10
{
_10
"fields": {},
_10
"error": {
_10
"code": "ORD005",
_10
"message": "The purchase cannot be done without items",
_10
"exception": null
_10
},
_10
"operationId": "673771c0-f5ba-4fa6-800d-bea836c51f93"
_10
}

400 - Bad Request (ORD002)

Message error example (code ORD002): "Invalid order form"

  • Issue: The orderFormId information is not valid.
  • Troubleshooting:
    • Verify that the orderFormId is correct.
    • Ensure that the orderFormId corresponds to an existing shopping cart.

400 - Bad Request (CHK0016)

Message error example (code CHK0016): "Payment value does not match with reference value"

  • Issue: The value and referenceValue fields have different values even without the use of interest in the payment.
  • Troubleshooting:
    • Confirm that the provided value and referenceValue align correctly.
    • Check if the interest rate is correctly configured.

404 - Not Found

Message error example: "The requested URL was not found on the server"

  • Issue: The requested URL was not found on the server.
  • Troubleshooting: Check if the endpoint used is correct.

500 - Internal Server Error

Message error example (code ORD005): "The purchase cannot be done without items"

  • Issue: The shopping cart (orderFormId) informed in the request does not have any item, making it impossible to create an order.
  • Troubleshooting:
    • Verify that the specified shopping cart has items.
    • Confirm that the orderFormId corresponds to a valid and non-empty shopping cart.
Response

_10
{
_10
"fields": {},
_10
"error": {
_10
"code": "ORD002",
_10
"message": "Invalid order form",
_10
"exception": null
_10
},
_10
"operationId": "f01ef909-8b81-4ffd-a91d-82be680d60ff"
_10
}

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