Budgets and allocations
Learn how to provision budgets and track spendings for B2B organizations using the Budgets API.
This feature is only available for stores using B2B Buyer Portal, which is currently available to select accounts.
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:
- Create a budget for a B2B unit.
- 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.
- 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
contextTypeandcontextId, 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 ascontextIdto correlate budgets with your external systems.
A typical end-to-end integration looks as follows:
- Your Integration Layer or back-office creates or updates budgets and allocations via the Budgets API, on behalf of the buyer.
- 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.
- Checkout determines how much to deduct from each allocation based on your buyer’s business rules.
- Checkout sends the selected budgets and allocation IDs to OMS.
- 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
POST- Create budgetGET- List budgetsGET- Get budgetPUT- Update budgetPUT- Update budget statusDELETE- Delete budget
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.
-
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.
-
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.
- name, description, and amount required.
-
Store the budget identifier by saving the returned id and keep it associated with your External Service budget identifier.
-
List and retrieve budgets
- Use GET List budgets to list budgets for a context with pagination.
- Use GET Get budget to retrieve full details, including balance and allocations.
-
Update the budget by using the PUT Update budget endpoint to update fields such as name, description, amount, or cycleConfiguration.
-
Control budget availability
- Use PUT Update budget status to activate or inactivate a budget.
- Use DELETE Delete budget only when you are sure the budget is no longer required.
Request example — Create budget
_32curl -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
- POST Create allocations batch
- GET List budget allocations
- GET Get allocation
- PUT Update allocation
- DELETE Delete allocation
Step-by-step
-
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.
-
Call the GET List budget allocations endpoint to retrieve allocations with pagination.
-
Call the GET Get allocation endpoint to retrieve full allocation details.
-
Call the PUT Update allocation endpoint to update fields such as amount, referenceId, or notificationSettings.
-
Call the DELETE Delete allocation endpoint to delete an allocation while preserving its history.
Request example — Create allocations batch
_37curl -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
-
Identify the context for the order by determining the contextType and contextId that represent its business context.
-
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).
-
Call the Query allocations endpoint
-
The request body contains an items array with all entities to match.
-
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.
-
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
_21curl -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}