Custom Fields integration
Learn how to configure and apply custom fields to B2B orders, items, and addresses using the Custom Fields API.
The Custom Fields API is only available for B2B Buyer Portal. Authorization from the Commerce Engineer of the account is required for use.
The Custom Fields integration enables B2B stores to capture additional business-specific information during checkout. This guide explains how to use the Custom Fields API to define, manage, and apply custom fields such as Cost Center, PO Number, or Location to orders.
The integration supports three main operations:
- Custom field settings: Define the structure and behavior of custom fields for a contract.
- Custom field values: Create predefined values for fields of type
option. - OrderForm application: Apply custom field values to shopping carts during checkout.
How it works
The custom fields integration works in three phases: configuration, value assignment, and checkout application.
Example flow:
-
Create a custom field setting for a contract:
_10POST /api/dataentities/customFieldSettings/documents?_schema=v2 -
Create values for the custom field (if type is
option):_10POST /api/dataentities/customFieldValues/documents?_schema=v2 -
Apply the custom field to an orderForm during checkout:
_10PUT /api/checkout/pub/orderForm/{orderFormId}/customFields/{entityType}/{entityId}
Custom fields can be applied at three levels:
order(entire order),item(individual cart items), oraddress(specific shipping addresses).
Create custom field settings
Use the POST Create custom field settings endpoint to create the configuration for a custom field associated with a specific contract. You define the field name, type, level, and whether it's required.
Request example
_11curl -X POST "https://{{accountName}}.myvtex.com/api/dataentities/customFieldSettings/documents?_schema=v2" \_11 -H "Content-Type: application/json" \_11 -H "VtexIdclientAutCookie: {{userToken}}" \_11 -d '{_11 "contractId": "2da4e9ab-050b-11f0-b37f-f4b136dbcce1",_11 "name": "Cost Center",_11 "enabled": true,_11 "required": true,_11 "level": "item",_11 "type": "option"_11 }'
Response body example
_10{_10 "Id": "customFieldSettings-89f1da93-6917-4cbf-894e-1f1399682826c",_10 "Href": "https://accountName.myvtex.com.br/api/dataentities/customFieldSettings/documents/89f1da93-6917-4cbf-894e-1f1399682826c?_schema=v2",_10 "DocumentId": "89f1da93-6917-4cbf-894e-1f1399682826c"_10}
Get custom field settings
Use the GET Get custom field settings endpoint to retrieve all custom field settings configured for a specific contract. Use the _where parameter to filter by contractId.
Request example
_10curl -X GET "https://{{accountName}}.myvtex.com/api/dataentities/customFieldSettings/search?_schema=v2&_fields=_all&_where=contractId={{contractId}}" \_10 -H "VtexIdclientAutCookie: {{userToken}}"
Response body example
_12[_12 {_12 "id": "34575ee8-80c1-458d-b75a-7492b36513e3",_12 "contractId": "2da4e9ab-050b-11f0-b37f-f4b136dbcce1",_12 "name": "Cost Center",_12 "enabled": true,_12 "required": true,_12 "level": "item",_12 "type": "option",_12 "createdIn": "2025-09-24T12:32:08.6879184Z"_12 }_12]
Create custom field value
Use the POST Create custom field value endpoint to create a value for custom fields of type option. Each value is associated with a specific custom field and contract.
Request example
_10curl -X POST "https://{{accountName}}.myvtex.com/api/dataentities/customFieldValues/documents?_schema=v2" \_10 -H "Content-Type: application/json" \_10 -H "VtexIdclientAutCookie: {{userToken}}" \_10 -d '{_10 "contractId": "2da4e9ab-050b-11f0-b37f-f4b136dbcce1",_10 "customFieldId": "89f1da93-6917-4cbf-894e-1f1399682826c",_10 "value": "CC1",_10 "description": "Cost Center 1 - Marketing Department"_10 }'
Response body example
_10{_10 "Id": "customFieldValues-07d12677-08d8-11f0-b37f-e1ae31409099",_10 "Href": "https://accountName.myvtex.com.br/api/dataentities/customFieldValues/documents/07d12677-08d8-11f0-b37f-e1ae31409099",_10 "DocumentId": "07d12677-08d8-11f0-b37f-e1ae31409099"_10}
Search custom field values
Use the GET Search custom field values to retrieve all values for a specific custom field. Use the _where parameter to filter by contractId and customFieldId.
Request example
_10curl -X GET "https://{{accountName}}.myvtex.com/api/dataentities/customFieldValues/search?_schema=v2&_fields=_all&_where=contractId={{contractId}} AND customFieldId=\"{{customFieldId}}\"&_sort=value ASC" \_10 -H "VtexIdclientAutCookie: {{userToken}}"
Response body example
_16[_16 {_16 "id": "e5130781-32ed-11f0-b37f-942217c27f9b",_16 "contractId": "1124b2d8-32eb-11f0-b37f-e2557e6b18d5",_16 "customFieldId": "a7f2b3d4-5c6e-7f89-0123-456789abcdef",_16 "value": "CC1",_16 "description": "Cost Center 1"_16 },_16 {_16 "id": "f6240892-43fe-22f1-c48a-053328d28f0c",_16 "contractId": "1124b2d8-32eb-11f0-b37f-e2557e6b18d5",_16 "customFieldId": "a7f2b3d4-5c6e-7f89-0123-456789abcdef",_16 "value": "CC2",_16 "description": "Cost Center 2"_16 }_16]
Apply custom field to orderForm
Use the PUT Create or update custom field in orderForm endpoint to apply a custom field value to an orderForm during checkout. The linkedEntity.type determines the level (order, item, or address) and linkedEntity.id identifies the specific entity.
Request example
_10curl -X PUT "https://{{accountName}}.myvtex.com/api/checkout/pub/orderForm/{{orderFormId}}/customFields/item/B2949D0A45244825B177D2F9F96DC711" \_10 -H "Content-Type: application/json" \_10 -H "VtexIdclientAutCookie: {{userToken}}" \_10 -d '{_10 "name": "Cost Center",_10 "value": "CC3",_10 "refId": "1dd9eeb8-23ed-42b3-8028-dc7745c01ada"_10 }'
Response body example
_19{_19 "customData": {_19 "customFields": [_19 {_19 "linkedEntity": {_19 "type": "item",_19 "id": "B2949D0A45244825B177D2F9F96DC711"_19 },_19 "fields": [_19 {_19 "name": "Cost Center",_19 "value": "CC3",_19 "refId": "1dd9eeb8-23ed-42b3-8028-dc7745c01ada"_19 }_19 ]_19 }_19 ]_19 }_19}
Apply custom fields in batch
Use the PUT Create or update custom fields in orderForm (batch) endpoint to apply multiple custom fields to an orderForm in a single request. Use this when you need to set fields at different levels simultaneously.
Request example
_13curl -X PUT "https://{{accountName}}.myvtex.com/api/checkout/pub/orderForm/{{orderFormId}}/customFields" \_13 -H "Content-Type: application/json" \_13 -H "VtexIdclientAutCookie: {{userToken}}" \_13 -d '[_13 {_13 "linkedEntity": { "type": "order" },_13 "fields": [{ "name": "PO Number", "value": "PO-2025-001" }]_13 },_13 {_13 "linkedEntity": { "type": "item", "id": "B2949D0A45244825B177D2F9F96DC711" },_13 "fields": [{ "name": "Cost Center", "value": "CC3" }]_13 }_13 ]'
Delete custom field from orderForm
Use the DELETE Delete custom field from orderForm endpoint to remove a specific custom field from an orderForm.
Request example
_10curl -X DELETE "https://{{accountName}}.myvtex.com/api/checkout/pub/orderForm/{{orderFormId}}/customFields/item/B2949D0A45244825B177D2F9F96DC711/Cost Center" \_10 -H "VtexIdclientAutCookie: {{userToken}}"
Field levels and types
Custom fields support different levels and types to accommodate various business requirements:
| Level | Description | Example use cases |
|---|---|---|
order | Applied to the entire order | PO Number, Project Code |
item | Applied to individual cart items | Cost Center, Budget Code |
address | Applied to specific shipping addresses | Delivery Instructions, Dock ID |
| Type | Description | Example use cases |
|---|---|---|
text | Free-form text input | Notes, reference numbers |
number | Numeric values only | Quantities, numeric codes |
option | Predefined list of values | Cost centers, departments |
For Budgets integration, only custom fields of type
optionare supported. This allows using the value ID for matching, enabling value renaming without breaking budget configurations.
Integration with other B2B features
Budgets
When configuring budgets that use custom fields, use entityType as CUSTOMFIELD and the custom field value id (DocumentId) as the entityId.
Buying Policies
When configuring buying policies, use the custom field value id in boolean expressions instead of the actual value. This allows renaming values without breaking existing policies.
Default Values
The Default Values integration allows you to pre-configure which custom field value should be automatically selected at checkout for each organizational unit. When a buyer logs in, the system automatically loads the configured default values, eliminating the need for manual selection.
How it works
The integration works in two phases:
- Configuration phase: The organization administrator defines which custom field values should be used as defaults for each organizational unit (org unit, contract, or user).
- Consumption phase: At buyer login, the shopper-session app fetches the configured default values and automatically applies them to checkout.
Entity format
To configure a custom field as a default value, use the following format in the defaultValues array:
_10{_10 "entity": "customFieldValues/{{customFieldId}}",_10 "entityValueId": "{{customFieldValueId}}"_10}
| Field | Description |
|---|---|
entity | Entity type identifier. For custom fields, use customFieldValues/ followed by the custom field setting ID (obtained when creating the field configuration). |
entityValueId | ID of the custom field value to be used as default (DocumentId returned when creating the value). |
Request example - Create default values with custom field
In this example, we configure the Cost Center "Marketing" as the default value for the organizational unit orgUnit-456:
_18curl -X POST "https://{{accountName}}.myvtex.com/api/dataentities/defaultValues/documents" \_18 -H "Content-Type: application/json" \_18 -H "Accept: application/json" \_18 -H "X-VTEX-API-AppKey: {{appKey}}" \_18 -H "X-VTEX-API-AppToken: {{appToken}}" \_18 -d '{_18 "id": "orgUnit-456",_18 "defaultValues": [_18 { _18 "entity": "address/shipping", _18 "entityValueId": "ed30b8d1-3128-4b0c-be56-f55b79592248" _18 },_18 { _18 "entity": "customFieldValues/89f1da93-6917-4cbf-894e-1f1399682826c", _18 "entityValueId": "07d12677-08d8-11f0-b37f-e1ae31409099" _18 }_18 ]_18 }'
In this example,
89f1da93-6917-4cbf-894e-1f1399682826cis the ID of the "Cost Center" custom field setting and07d12677-08d8-11f0-b37f-e1ae31409099is the ID of the "Marketing" value.
Response example
_10{_10 "Id": "orgUnit-456",_10 "Href": "https://accountName.myvtex.com/api/dataentities/defaultValues/documents/orgUnit-456",_10 "DocumentId": "orgUnit-456"_10}
Update default values
To update the default values of an existing organizational unit:
_13curl -X PATCH "https://{{accountName}}.myvtex.com/api/dataentities/defaultValues/documents/orgUnit-456" \_13 -H "Content-Type: application/json" \_13 -H "Accept: application/json" \_13 -H "X-VTEX-API-AppKey: {{appKey}}" \_13 -H "X-VTEX-API-AppToken: {{appToken}}" \_13 -d '{_13 "defaultValues": [_13 { _13 "entity": "customFieldValues/89f1da93-6917-4cbf-894e-1f1399682826c", _13 "entityValueId": "f6240892-43fe-22f1-c48a-053328d28f0c" _13 }_13 ]_13 }'
Remove default values
To completely remove the default values of an organizational unit:
_10curl -X DELETE "https://{{accountName}}.myvtex.com/api/dataentities/defaultValues/documents/orgUnit-456" \_10 -H "Accept: application/json" \_10 -H "X-VTEX-API-AppKey: {{appKey}}" \_10 -H "X-VTEX-API-AppToken: {{appToken}}"
Complete integration flow
The diagram below illustrates the complete flow from creating the custom field to applying the default value at checkout:
Default Values permissions
The following License Manager permissions are required for Default Values operations:
| Operation | Required resources |
|---|---|
| Create default values | Insert or update documents (not remove), Full access to all documents, or Master Data administrator |
| Read default values | Read-only documents, Insert or update document (not remove), Full access to all documents, or Master Data administrator |
| Update default values | Insert or update documents (not remove), Full access to all documents, or Master Data administrator |
| Delete default values | Full access to all documents or Master Data administrator |
Only custom fields of type
optionare supported for default value configuration. This ensures that the value ID is used for matching, allowing values to be renamed without breaking configurations.
If a custom field's name or value is altered after an order has been placed, these changes will not be reflected in the existing order. The order retains the original values.
Permissions
The following License Manager resources are required:
| Operation | Required resources |
|---|---|
| Create/Update settings or values | Insert or update documents (not remove), Full access to all documents, or Master Data administrator |
| Read settings or values | Read-only documents, Insert or update documents (not remove), Full access to all documents, or Master Data administrator |
| Delete settings or values | Full access to all documents or Master Data administrator |
| OrderForm operations | Read Shopping Cart |
All resources belong to the Dynamic Storage product, except OrderForm operations which belong to the Checkout product.