# Check Whether an Order Is Within Budget

Last updated: 2026-11-26

Submit a proposed order payload to check whether it is within budget.

 

## Request

 

` POST https://api.myzahara.net/api/{businessUnitApiKey}/BusinessBudget/OrderWithinBudget `

 

Send ` Accept: application/json ` and ` Content-Type: application/json `.

 

Send a JSON object from ZAHARA\_REQUEST\_FILE. Replace the example user, supplier, division, currency and coding references with values belonging to the selected business unit. The new-order example uses zero for DocumentId and line-item identifiers.

 

### Request body example

 

Replace the fictional identifiers and values with those for your business.

 

```json
{
  "RequisitorId": 101,
  "TotalNetValue": 100,
  "TotalGrossValue": 120,
  "RequiredDate": "2026-01-15T00:00:00Z",
  "DocumentId": 0,
  "BusinessDivisionId": 201,
  "SupplierId": 301,
  "DateCreated": "2026-01-01T12:00:00Z",
  "LineItems": [
    {
      "LineItemId": 0,
      "DocumentId": 0,
      "Quantity": 1,
      "Price": 100,
      "Description": "Example item",
      "NominalCodeId": 401,
      "TaxCodeId": 501,
      "TaxPercentage": 20,
      "TaxValue": 20,
      "NetValue": 100,
      "QuantityReceived": 0,
      "DiscountPercentage": 0,
      "DivisionId": 201
    }
  ],
  "CurrencyId": 1
}
```

 

### Request fields

 

| Field | Example type | Use |
| --- | --- | --- |
| RequisitorId | number | Numeric requesting-user reference. |
| TotalNetValue | number | Proposed document net total. |
| TotalGrossValue | number | Proposed document gross total. |
| RequiredDate | string | Required date-time for the order. |
| DocumentId | number | The new-order example uses zero. |
| BusinessDivisionId | number | Numeric business-division reference. |
| SupplierId | number | Numeric supplier reference. |
| DateCreated | string | Record creation date-time. |
| LineItems | array | Order lines containing quantities, prices, coding references and tax/net values. |
| CurrencyId | number | Numeric currency reference. |

 

## Authentication and scope

 

| Parameter | Location | Meaning |
| --- | --- | --- |
| businessUnitApiKey | URL path | Business-unit API key; never a numeric ID. |

 

Keep credentials in an environment variable or secret store. The API key appears in the request path, so redact URLs in logs, proxy traces and error reporting. Do not give real keys to a coding agent in a prompt or documentation URL. Use the correct key scope; do not assume a tenancy key works in a business-unit method.

 

## Working examples

 

Set the environment variables below, then run the example in your preferred language. Save the request body as a JSON file and set ZAHARA\_REQUEST\_FILE to its path. Set ZAHARA\_API\_BASE\_URL explicitly to the API origin you intend to use. Use a secure terminal for business data.

 

| Environment variable | Purpose |
| --- | --- |
| ZAHARA\_BUSINESS\_UNIT\_API\_KEY | Required API key; store privately. |
| ZAHARA\_REQUEST\_FILE | Path to a JSON object file; review its references before running. |
| ZAHARA\_API\_BASE\_URL | API origin for the selected environment, without an /api path. |

 

### cURL

 

Requires cURL 7.76.0+ for ` --fail-with-body `. It prints the complete response, including error JSON on an HTTP failure. Use a secure development terminal.

 

```sh
# cURL 7.76.0+. Set the environment variables documented below.
# Send the request to the intended environment and business unit.
curl --fail-with-body --silent --show-error --max-time 30 \
  --request POST \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data-binary "@${ZAHARA_REQUEST_FILE:?Set ZAHARA_REQUEST_FILE}" \
  "${ZAHARA_API_BASE_URL:?Set ZAHARA_API_BASE_URL}/api/${ZAHARA_BUSINESS_UNIT_API_KEY:?Set ZAHARA_BUSINESS_UNIT_API_KEY}/BusinessBudget/OrderWithinBudget"
```

 

### JavaScript (Node.js 22+)

 

Uses built-in fetch and a 30-second timeout; no extra packages are needed. Check the HTTP status and inspect the parsed result before accessing fields.

 

```javascript
// Node.js 22+. Standard library only.
import { readFileSync } from 'node:fs';
function required(name) {
  const value = process.env[name];
  if (!value) throw new Error('Set ' + name);
  return value;
}
const key = required('ZAHARA_BUSINESS_UNIT_API_KEY');
// Send the request to the intended environment and business unit.
const base = required('ZAHARA_API_BASE_URL').replace(/\/$/, '');
let path = "BusinessBudget/OrderWithinBudget";

const url = new URL(base + '/api/' + encodeURIComponent(key) + '/' + path);

const payload = JSON.parse(readFileSync(required('ZAHARA_REQUEST_FILE'), 'utf8'));
let response;
try {
  response = await fetch(url, {
    method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
    body: JSON.stringify(payload),
    signal: AbortSignal.timeout(30000), redirect: 'error'
  });
} catch { throw new Error('Zahara request failed or timed out; URL omitted to protect the key'); }
if (!response.ok) throw new Error('Zahara returned HTTP ' + response.status);
const text = await response.text();
// Some methods may return an empty successful body. Do not assume a JSON shape.
const result = text.trim() ? JSON.parse(text) : null;
// Use a secure console; response fields may include financial or business data.
console.log(JSON.stringify(result, null, 2));
```

 

### Python 3 (standard library)

 

Rejects redirects and reports HTTP errors without including the credential-bearing URL.

 

```python
# Python 3. Standard library only.
import json
import os
from urllib.parse import quote, urlencode
from urllib.request import Request, build_opener, HTTPRedirectHandler
from urllib.error import HTTPError, URLError

class NoRedirect(HTTPRedirectHandler):
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        return None

def required(name):
    value = os.environ.get(name)
    if not value:
        raise SystemExit('Set ' + name)
    return value

key = required('ZAHARA_BUSINESS_UNIT_API_KEY')
# Send the request to the intended environment and business unit.
base = required('ZAHARA_API_BASE_URL').rstrip('/')
path = "BusinessBudget/OrderWithinBudget"

url = base + '/api/' + quote(key, safe='') + '/' + path

with open(required('ZAHARA_REQUEST_FILE'), encoding='utf-8') as file:
    payload = json.load(file)
data = json.dumps(payload).encode('utf-8')
request = Request(url, data=data, method='POST',
    headers={'Accept': 'application/json', 'Content-Type': 'application/json'})
try:
    with build_opener(NoRedirect).open(request, timeout=30) as response:
        text = response.read().decode('utf-8')
except HTTPError as error:
    raise SystemExit('Zahara returned HTTP ' + str(error.code)) from None
except URLError:
    raise SystemExit('Zahara request failed; URL omitted to protect the key') from None
result = json.loads(text) if text.strip() else None
# Use a secure console: the result may contain confidential data.
print(json.dumps(result, indent=2))
```

 

## Successful response

 

Check the HTTP status before processing the budget decision. Keep a negative decision separate from a failed HTTP request, and keep the decision separate from subsequent order creation or budget application.

 

## Handling failures

 

Check the HTTP status before reading the result. Handle timeouts and unexpected response formats separately from valid empty results or negative decisions. The samples make one request and do not automatically retry.

 

After an uncertain outcome, retrieve the relevant records before repeating a request that can change business data.

 

## Integration notes

 

- Keep budget-decision processing separate from creating an order, applying invoice budgets or reserving funds.
- Provide consistent line quantities, prices, net values, tax values and document totals.
- Process the returned decision only after checking the HTTP status. Keep a negative budget decision separate from a failed request.
