Documentation
Feedback
Guides
API Reference

Guides
Guides
B2B
B2B Buyer Portal

Budgets and allocations

Learn how to provision budgets and track spendings for B2B organizations using the Budgets API.

The Budgets feature is only available for B2B Buyer Portal. Authorization from the Commerce Engineer of the account is required for usage.

The Budgets API allows buyers to track spending across different parts of your organization by creating budgets and subdividing them into allocations that are attached to specific entities, such as users, addresses, or business accounting fields like cost center or purchase order number.

This integration guide explains how to provision budgets for a given business context, distribute those budgets into allocations, and query allocations at checkout time so your ecommerce and back-office systems can consistently track spending rules. It focuses on the Budget and Allocations endpoints of the Budgets API.

The budget functionality is intended for buyers using the Organization Account interface. Integration is only required when the merchant needs to create budgets on behalf of the buyer, support budget consumption, or implement a headless checkout.

Prerequisites

Before integrating with the Budgets API, make sure the following requirements are met.

Permissions required

To use the Budgets API, the integration must have the required License Manager permissions. Without these permissions, all API requests will fail with a 403 Forbidden response.

  • ManageBudgets: Required to create, update, delete, and query budgets and allocations.
  • ViewBudget: Required for read-only access to budgets.

Assign these permissions to dedicated integration roles rather than shared roles to ensure secure, auditable access.

How it works

To use the Budgets API, follow this lifecycle:

  1. Create a budget for a B2B unit.
  2. Create allocations under that budget, each linked to a specific entity, such as a user, address, cost center, and so on.

    During order processing, Checkout and OMS consume allocations through Transactions or Reservations + Transactions, decreasing available balances.

  3. Retrieve statements for audits and reporting, not covered in this guide.

Each budget and allocation has:

  • A total amount and remaining balance.
  • A validity window defined by start and end dates.
  • A status, for example, ACTIVE or INACTIVE, that controls whether it can be used.

Budgets and allocations are always scoped by contextType and contextId, which represent the B2B business context that owns the budget. For B2B scenarios, contextType must be UNIT. Use a stable, unique identifier from your master data as contextId to correlate budgets with your external systems.

A typical end-to-end integration looks as follows:

  1. Your Integration Layer or back-office creates or updates budgets and allocations via the Budgets API, on behalf of the buyer.
  2. Checkout receives an order, identifies the relevant entities such as cost center, buyer, address, and so on, and calls the Query allocations endpoint to retrieve applicable allocations.
  3. Checkout determines how much to deduct from each allocation based on your buyer’s business rules.
  4. Checkout sends the selected budgets and allocation IDs to OMS.
  5. OMS creates Transactions and Refunds when needed against those allocations.

If you deactivate or delete a budget or allocation that is still referenced by your ERP or checkout integration, queries may stop returning it, and purchases may be blocked unexpectedly.

End-to-end integration sequence

Budget provisioning flow

The budget provisioning flow creates and maintains the main spending envelope for a given business context, such as a B2B unit. A budget defines the total amount available over a period and can include optional initial allocations created in a single call.

When to use this flow

Use this flow in the following scenarios:

  • Create or synchronize budgets from an external application.
  • Change the budget amount, description, or period.
  • Activate or deactivate a budget without removing its historical data.

Main endpoints involved

Instructions

Follow the steps below to create and manage a budget for a given business context (for example, a B2B unit) using the Budgets API.

  1. Choose the budget context:

    • Decide which context type and ID will own the budget, for example, contextType = UNIT, contextId = "unit-123". For B2B scenarios, contextType must be UNIT.
    • Ensure the same values are used consistently by all systems that will interact with this budget.
  2. Create the budget by calling the POST Create budget endpoint with the required fields:

    • name, description, and amount required.
      • cycleConfiguration start and end dates, auto-reset, carry-over.
      • Optional allocations array if you want to create initial allocations in the same request.
  3. Store the budget identifier by saving the returned id and keep it associated with your External Service budget identifier.

  4. List and retrieve budgets

  5. Update the budget by using the PUT Update budget endpoint to update fields such as name, description, amount, or cycleConfiguration.

  6. Control budget availability

Request example — Create budget


_32
curl -X POST "https://{{accountName}}.{{environment}}.com/api/budgets/UNIT/unit-123" \
_32
-H "X-VTEX-API-AppKey: {{appKey}}" \
_32
-H "X-VTEX-API-AppToken: {{appToken}}" \
_32
-H "Content-Type: application/json" \
_32
-H "Accept: application/json" \
_32
-d '{
_32
"name": "Q2 Marketing Budget",
_32
"description": "Quarterly budget for unit-123 marketing activities",
_32
"amount": 50000,
_32
"cycleConfiguration": {
_32
"startDate": "2025-04-01T00:00:00.0000000Z",
_32
"endDate": "2025-04-08T00:00:00.0000000Z",
_32
"autoResetOnPeriodEnd": true,
_32
"carryOverBalance": true
_32
},
_32
"notificationSettings": {
_32
"enable": false,
_32
"thresholds": [
_32
{
_32
"type": "PERCENT",
_32
"Value": 99
_32
}
_32
],
_32
"recipients": [
_32
{
_32
"type": "Email",
_32
"identifier": "user1@email.com"
_32
}
_32
]
_32
}
_32
}
_32
'

Response example


_35
{
_35
"id": "0197c1e3-a82f-7746-8614-bf518e625a92",
_35
"name": "Q2 Marketing Budget",
_35
"description": "Quarterly budget for unit-123 marketing activities",
_35
"balance": {
_35
"amount": 50000,
_35
"balanceAdjustment": 0,
_35
"remaining": 50000
_35
},
_35
"cycleConfiguration": {
_35
"startDate": "2025-04-01T00:00:00.0000000Z",
_35
"endDate": "2025-04-08T00:00:00.0000000Z",
_35
"autoResetOnPeriodEnd": true,
_35
"carryOverBalance": true,
_35
"nextRenewal": "2025-04-08T00:00:00.0000000Z"
_35
},
_35
"notificationSettings": {
_35
"enable": false,
_35
"thresholds": [
_35
{
_35
"type": "PERCENT",
_35
"Value": 99
_35
}
_35
],
_35
"recipients": [
_35
{
_35
"type": "Email",
_35
"identifier": "user1@email.com"
_35
}
_35
]
_35
},
_35
"status": "ACTIVE",
_35
"contextType": "UNIT",
_35
"contextId": "093f29ac-7a1b-4d6b-a79a-48f89cf73d14"
_35
}

Allocation management flow

The allocation management flow subdivides a budget into one or more allocations, each tied to a specific entity such as a cost center, a user, or a shipping address. Each allocation has its own amount, optional notification settings, and status.

Allocations allow you to define fine-grained spending rules while still tracking the total budget for the broader context.

When to use this flow

  • To distribute a budget across multiple entities, such as cost centers or projects.
  • To adjust the amount, status, or notification rules for existing allocations.

Main endpoints involved

Step-by-step

  1. Create allocations for a budget

    • Use POST Create allocations batch.
    • The body contains an allocations array. Each allocation includes:
      • linkedEntity: Linked entity information such as id = "cost-center-001", type = "CostCenter".
      • amount: allocation amount.
      • referenceId: ID of the related resource, such as a contract.
      • Optional notificationSettings.
  2. Call the GET List budget allocations endpoint to retrieve allocations with pagination.

  3. Call the GET Get allocation endpoint to retrieve full allocation details.

  4. Call the PUT Update allocation endpoint to update fields such as amount, referenceId, or notificationSettings.

  5. Call the DELETE Delete allocation endpoint to delete an allocation while preserving its history.

Request example — Create allocations batch


_37
curl -X POST "https://{{accountName}}.{{environment}}.com/api/budgets/UNIT/unit-123/ffc4575e-5e5c-420e-bcb7-bf4a271f5d60/allocations/batch" \
_37
-H "X-VTEX-API-AppKey: {{appKey}}" \
_37
-H "X-VTEX-API-AppToken: {{appToken}}" \
_37
-H "Content-Type: application/json" \
_37
-H "Accept: application/json" \
_37
-d '{
_37
"allocations": [
_37
{
_37
"linkedEntity": {
_37
"id": "PO-number-2025-001-01",
_37
"type": "PO Number"
_37
},
_37
"referenceId": "21795f6f-5378-11f0-b37f-842fce820b77",
_37
"contractId": "21795f6f-5378-11f0-b37f-842fce820b77",
_37
"amount": 2040
_37
},
_37
{
_37
"linkedEntity": {
_37
"id": "PO-number-2025-002-02",
_37
"type": "PO Number"
_37
},
_37
"referenceId": "21795f6f-5378-11f0-b37f-842fce820b77",
_37
"amount": 2040,
_37
"notificationSettings": [
_37
{
_37
"type": "AMOUNT",
_37
"threshold": 121,
_37
"recipients": [
_37
{
_37
"email": "user1@email.com"
_37
}
_37
]
_37
}
_37
]
_37
}
_37
]
_37
}

Response example


_22
{
_22
"budgetId": "0197c1eb-3f62-73e1-93a2-6fa5d37b74f1",
_22
"allocations": [
_22
{
_22
"id": "0197c1f8-082a-776a-ade2-992badbcc96a",
_22
"budgetId": "0197c1eb-3f62-73e1-93a2-6fa5d37b74f1",
_22
"linkedEntity": {
_22
"id": "cost-center-001",
_22
"type": "CostCenter"
_22
},
_22
"balance": {
_22
"amount": 30000,
_22
"balanceAdjustment": 0,
_22
"remaining": 30000
_22
},
_22
"status": "ACTIVE",
_22
"referenceId": "contract-2025-CC001",
_22
"contextType": "UNIT",
_22
"contextId": "093f29ac-7a1b-4d6b-a79a-48f89cf73d14"
_22
}
_22
]
_22
}

Checkout allocation lookup flow

The checkout allocation lookup flow allows Checkout or any other consuming system to discover which allocations apply to a given purchase. It uses the Query allocations endpoint to match a combination of entities, such as cost centers, users, or addresses, against existing allocations.

Checkout identifies and groups applicable allocations, while OMS processes transactions and refunds. If configured, Order Authorization can enforce budget rules.

When to use this flow

  • Determine which budgets and allocations should fund a given order.
  • Centralize budget logic in the Budgets API instead of hardcoding it in Checkout or OMS.
  • Support complex scenarios where multiple entities determine the applicable budget.

Endpoint involved

Instructions

  1. Identify the context for the order by determining the contextType and contextId that represent its business context.

  2. Identify the relevant entities that influence budget selection, such as user ID, shipping address, and accounting fields like purchase order number or project code, and define for each entity its id and semantic type (for example, User, Address, CostCenter, or PO Number).

  3. Call the Query allocations endpoint

  4. Interpret the response by reading the items array returned by the API, which includes budgetId, allocationId, the linkedEntity, and budget and allocation balance information, and decide how much to deduct from each allocation based on its applicability to the order, item, or address.

  5. Pass the result to OMS by including the selected budgetId and allocationId values in the order so that OMS can create transactions.

Request example — Query allocations


_21
curl -X POST "https://{{accountName}}.{{environment}}.com/api/budgets/UNIT/unit-123/allocations/query" \
_21
-H "X-VTEX-API-AppKey: {{appKey}}" \
_21
-H "X-VTEX-API-AppToken: {{appToken}}" \
_21
-H "Content-Type: application/json" \
_21
-H "Accept: application/json" \
_21
-d '{
_21
"items": [
_21
{
_21
"id": "cost-center-001",
_21
"type": "CostCenter"
_21
},
_21
{
_21
"id": "user-789",
_21
"type": "User"
_21
},
_21
{
_21
"id": "PO-456",
_21
"type": "PO Number"
_21
}
_21
]
_21
}'

Response example


_28
{
_28
"items": [
_28
{
_28
"budgetId": "ffc4575e-5e5c-420e-bcb7-bf4a271f5d60",
_28
"allocationId": "41b9ec1e-af0a-45f6-b3fb-351f700a63aa",
_28
"linkedEntity": {
_28
"id": "cost-center-001",
_28
"type": "CostCenter"
_28
},
_28
"budgetBalance": {
_28
"amount": 50000,
_28
"balanceAdjustment": 0,
_28
"remaining": 50000
_28
},
_28
"cycleConfiguration": {
_28
"startDate": "2025-04-01T00:00:00.0000000Z",
_28
"endDate": "2025-04-08T00:00:00.0000000Z",
_28
"autoResetOnPeriodEnd": true,
_28
"carryOverBalance": true
_28
},
_28
"allocationBalance": {
_28
"amount": 30000,
_28
"balanceAdjustment": 0,
_28
"remaining": 30000
_28
}
_28
}
_28
]
_28
}

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