Adding a second address for invoicing an order

For B2B businesses, it is common to add to the invoice an address that is different from the one registered for delivery, since the location where the product will be received is often different from the billing address.

VTEX Admin allows you to add a second address only in the case of Pickup Points because there will be only one address for the invoice. For other cases, adding a second address must be done via API, using the orderForm object.

The orderForm is the main object processed by VTEX Checkout, and one of the most important data structures in VTEX stores' architecture.

There are two ways to manipulate data from the orderForm to enter a second address:

  • Using the vtex.js library
  • Through API REST

🚧

Although it is possible to create a custom interface superimposed on that of VTEX containing the second address field, we do not recommend it, because it increases the chances of errors in order management.


vtex.js

The vtex.js is a library of JavaScript functions that will do the API requests. The function used for this is the sendAttachment. Fore more information, see the specific library documentation.

API REST

To add a second address to an order via API, make a POST request to the endpoint below:

/api/checkout/pub/orderForm/{{orderFormId}}/attachments/invoiceData

The {{orderFormId}} value must be replaced by the ID of the orderForm that you want to manipulate.

In the orderForm object there is the object invoiceData, which contains information about the order's invoice and contains the field address. This field must be set with the second address you wish to add. The request body looks like the example below:


{
    "address": {
        "postalCode": "22250-040",
        "city": "Rio de Janeiro",
        "state": "RJ",
        "country": "BRA",
        "street": "Praia Botafogo",
        "number": "300",
        "neighborhood": "Botafogo",
        "complement": null,
        "reference": null,
        "geoCoordinates": [
            -43.18218231201172,
            -22.94549560546875
        ]
    }
}

Did this page help you?