Skip to documentation
Zahara DevelopersAPI documentation
DocumentationBudgets
Download .md
Budgets

Get Budget by Invoice ID

Last updated

Retrieve the budget-selection information associated with an invoice.

Request

GET https://api.myzahara.net/api/{businessUnitApiKey}/BusinessBudget/GetBudgetsForInvoice/{invoiceId}

Send Accept: application/json. No request body is required.

Supply the numeric invoice DocumentId from the same business unit, rather than its displayed invoice number or purchase-order number.

Authentication and scope

Parameter Location Meaning
businessUnitApiKey URL path Business-unit API key; never a numeric ID.
invoiceId URL path Integer ≥ 1. Use an authorised reference from the same context.

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. Use a secure terminal for business data.

Environment variable Purpose
ZAHARA_BUSINESS_UNIT_API_KEY Required API key; store privately.
ZAHARA_INVOICE_ID invoiceId.

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.

# cURL 7.76.0+. Set the environment variables documented below.
# Treat response data as confidential. Keep keys out of logs.
curl --fail-with-body --silent --show-error --max-time 30 \
  --request GET \
  --header 'Accept: application/json' \
  "https://api.myzahara.net/api/${ZAHARA_BUSINESS_UNIT_API_KEY:?Set ZAHARA_BUSINESS_UNIT_API_KEY}/BusinessBudget/GetBudgetsForInvoice/${ZAHARA_INVOICE_ID:?Set ZAHARA_INVOICE_ID}"

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.

// Node.js 22+. Standard library only.
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');
const base = 'https://api.myzahara.net';
let path = "BusinessBudget/GetBudgetsForInvoice/{invoiceId}";
const invoiceId = required('ZAHARA_INVOICE_ID');
if (!/^\d+$/.test(invoiceId) || !Number.isSafeInteger(Number(invoiceId)) || Number(invoiceId) < 1) throw new Error('Invalid ZAHARA_INVOICE_ID');
path = path.replace('{invoiceId}', encodeURIComponent(invoiceId));
const url = new URL(base + '/api/' + encodeURIComponent(key) + '/' + path);


let response;
try {
  response = await fetch(url, {
    method: 'GET', headers: { Accept: 'application/json' },
    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 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')
base = 'https://api.myzahara.net'
path = "BusinessBudget/GetBudgetsForInvoice/{invoiceId}"
invoiceId = required('ZAHARA_INVOICE_ID')
if not invoiceId.isascii() or not invoiceId.isdigit() or int(invoiceId) < 1:
    raise SystemExit('Invalid ZAHARA_INVOICE_ID')
path = path.replace('{invoiceId}', quote(invoiceId, safe=''))
url = base + '/api/' + quote(key, safe='') + '/' + path


request = Request(url, method='GET',
    headers={'Accept': '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

Use the invoice selection data to associate budget references and options with the relevant invoice. Keep budget references separate from full budget definitions.

Budget selection fields

Field Use
InvoiceId Associate the selection with its invoice.
DivisionBudgets Division-budget references.
ProjectBudgets Project-budget references.
ApplyInvoiceOption Invoice-budget option code.
OrderIsMatched Order-matching indicator.

Handling failures

An invalid key returns HTTP 401. A business unit that does not support invoice budgets can return HTTP 500 with an unsupported-business-unit message. Check the target unit’s budget configuration and redact any credential echoed in the error.

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.

Integration notes

  • This method requires support for invoice budgets in the target business unit. Check the budget configuration if the API reports that invoice budgets are not supported.
  • Treat division and project budget values as references, rather than complete budget-definition objects.
  • Keep an unsupported-business-unit error separate from an empty budget selection.
.md
Take this page to your coding agent.

Copy a clean Markdown URL that follows the published article.