# Make your first request

Start with a read-only GET request. This example retrieves the business units belonging to your tenancy.

## Before you start

You need access to a Zahara tenancy and its tenancy API key. Zahara distinguishes tenancy keys from business-unit keys: this request uses the tenancy key. Obtain the appropriate key through your Zahara administrator. Store it in the ZAHARA_TENANCY_API_KEY environment variable, rather than in source code.

The examples below call the production API. Use a tenancy you are authorised to access. Do not paste your key into an AI conversation, documentation URL or shared screenshot.

## The request

`GET https://api.myzahara.net/api/{tenancyApiKey}/BusinessUnit/GetAll`

Send `Accept: application/json`. This request has no body. It reads data; it does not create or update a business unit.

## cURL

Requires a version of cURL that supports `--fail-with-body` (7.76.0 or later).

```sh
# Set your tenancy API key in the environment first.
curl --fail-with-body --silent --show-error --max-time 30 \
  --header 'Accept: application/json' \
  "https://api.myzahara.net/api/${ZAHARA_TENANCY_API_KEY:?Set your tenancy API key}/BusinessUnit/GetAll"
```

## JavaScript

Uses Node.js 22+ and its built-in fetch. No additional packages are required.

```javascript
// Node.js 22+ · read business units for your tenancy
const key = process.env.ZAHARA_TENANCY_API_KEY;
if (!key) throw new Error('Set ZAHARA_TENANCY_API_KEY');

const response = await fetch(
  'https://api.myzahara.net/api/' +
    encodeURIComponent(key) + '/BusinessUnit/GetAll',
  {
    headers: { Accept: 'application/json' },
    signal: AbortSignal.timeout(30000),
    redirect: 'error'
  }
);
if (!response.ok) {
  throw new Error('Zahara returned HTTP ' + response.status);
}
const units = await response.json();
// Settings may contain credentials. Select only the fields you need.
console.log(units.map(({ BusinessUnitId, Name, Archived }) =>
  ({ BusinessUnitId, Name, Archived })
));
```

## Python

Uses the Python 3 standard library.

```python
# Python 3 · no additional packages
import json
import os
from urllib.parse import quote
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

key = os.environ.get('ZAHARA_TENANCY_API_KEY')
if not key:
    raise SystemExit('Set ZAHARA_TENANCY_API_KEY')

request = Request(
    'https://api.myzahara.net/api/' + quote(key, safe='')
    + '/BusinessUnit/GetAll',
    headers={'Accept': 'application/json'}
)
try:
    with build_opener(NoRedirect).open(request, timeout=30) as response:
        units = json.load(response)
except HTTPError as error:
    raise SystemExit('Zahara returned HTTP ' + str(error.code)) from None
except URLError:
    raise SystemExit('Could not reach Zahara') from None

# Settings may contain credentials. Select only the fields you need.
print(json.dumps([
    {name: unit.get(name) for name in ('BusinessUnitId', 'Name', 'Archived')}
    for unit in units
], indent=2))
```

## Read the response

A successful response is a JSON array of business units. Returned units include business settings; some settings may contain credentials. Only log the fields your integration needs. Archived business units can be included, so inspect the Archived flag if you need active units only.

See [Get Business Units](https://help.zaharasoftware.com/api-docs/get-business-units.md) for the currently published reference. Documentation is being expanded; do not assume every resource returns the same shape.

## If the request fails

Check the HTTP status before parsing JSON. Confirm the hostname, endpoint and key scope. A nonexistent tenancy key can return HTTP 404, so do not assume authentication errors always use 401. The exact response depends on the failure.

Because the key appears in the URL path, mask request URLs in logs and monitoring. Do not print an exception that exposes the full request URL. Do not automatically retry a create or update request when adapting these examples.
