# TrackerPro External API

Host: `https://externalapi.trackerpro.co.uk`

Read-only CRM integration using OAuth2 client credentials. Create an OAuth client in TrackerPro Admin to get a `client_id` and `client_secret` (secret is shown once).

## Create client id and secret in Admin

You need a TrackerPro Admin login for the company that should share CRM data.

### Navigation

1. Sign in to TrackerPro Admin for your company.
2. Open **Integrations** in the left menu.
3. Click **External API**.
4. Stay on the **OAuth clients** tab (default).

Direct path (same company session): `/ExternalApi`

### Create a client

1. In **Create OAuth client**, enter a **Name** (for example `Partner CRM sync`).
2. Confirm **Scopes** (space-separated). Default grants all read scopes:
   `customers:read installations:read jobs:read quotes:read calls:read`
3. Optionally set **Expires** (UTC) if the client should stop working after a date.
4. Click **Create client**.
5. A yellow warning appears: **Save these credentials now** with:
   - `client_id`
   - `client_secret`
6. Copy both into your integration, Postman, or Bruno variables immediately.
7. The secret is hashed in the database and **will not be shown again**. If you lose it, use **Rotate** on that client row to issue a new secret (old secret and refresh tokens stop working).

### After create

- Put `client_id` and `client_secret` into collection variables (see Downloads below).
- Run **Get Access Token** against `POST /oauth/token`, then call `/v1/...` with `Authorization: Bearer {access_token}`.
- Use the **Usage** and **Logs** tabs on the same Admin page to monitor calls for this company.
- **Rotate** - new secret once; invalidates existing refresh tokens for that client.
- **Revoke** - disables the client; access and refresh tokens stop working.

## Downloads

- [Help PDF (print / save as PDF)](/help/pdf)
- [Postman collection](/help/postman) - import into Postman
- [Bruno collection (zip)](/help/bruno) - unzip and open the folder in Bruno
- [Swagger](/swagger)
- [Markdown source](/help/markdown)

### Collection variables

Both Postman and Bruno collections use shared variables:

- `baseUrl` - API host (default production URL)
- `client_id` - OAuth client id from Admin
- `client_secret` - OAuth client secret (shown once)
- `access_token` - Bearer token (auto-filled after Get Access Token)
- `refresh_token` - Refresh token (auto-filled / rotated)
- `account` - Customer account reference for get/list filters
- `installationId` / `jobId` / `quoteId` / `callId` - Resource ids
- `page` / `pageSize` - paging (pageSize max 100)
- `q` - free-text search (customers + installations only; see List filters)
- `status` - exact status filter (jobs / quotes / calls)

Postman: edit Collection variables, then run OAuth > Get Access Token first.

Bruno: pick environment Production or Local, set client_id / client_secret, then run Get Access Token.

## Scopes

- `customers:read`
- `installations:read`
- `jobs:read`
- `quotes:read`
- `calls:read`

## Obtain an access token

`POST /oauth/token` with `application/x-www-form-urlencoded` or JSON.

```
curl -X POST https://externalapi.trackerpro.co.uk/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
```

Response:

```
{
  "access_token": "...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "...",
  "scope": "customers:read installations:read jobs:read quotes:read calls:read"
}
```

HTTP Basic auth for client_id:client_secret is also accepted on the token endpoint.

## Refresh

```
curl -X POST https://externalapi.trackerpro.co.uk/oauth/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=refresh_token&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&refresh_token=YOUR_REFRESH"
```

Refresh tokens rotate on each use. Revoking the client invalidates all refresh tokens.

## Call CRM endpoints

```
curl "https://externalapi.trackerpro.co.uk/v1/customers?q=acme&page=1&pageSize=25" \
  -H "Authorization: Bearer ACCESS_TOKEN"
```

### List filters

All lists: `page`, `pageSize` (max 100).

- `GET /v1/customers?q=` - free-text contains on **account reference**, **customer name**, **address 5**
- `GET /v1/installations?q=` - free-text contains on **property name**, **address 5**, **account ref**
- `GET /v1/installations?account=` - exact account reference
- `GET /v1/jobs|quotes|calls?account=` - exact account reference
- `GET /v1/jobs|quotes|calls?installationId=` - exact installation id (AlarmRefNo)
- `GET /v1/jobs|quotes|calls?status=` - exact status (for example `Open`)

`q` is not supported on jobs, quotes, or calls.

More samples:

```
curl "https://externalapi.trackerpro.co.uk/v1/installations?q=High%20Street&page=1&pageSize=25" \
  -H "Authorization: Bearer ACCESS_TOKEN"

curl "https://externalapi.trackerpro.co.uk/v1/jobs?account=CUST001&status=Open&page=1&pageSize=25" \
  -H "Authorization: Bearer ACCESS_TOKEN"
```

Other resources:

- `GET /v1/me` (client id, client name, company label, scopes, token expiry only)
- `GET /v1/customers` / `GET /v1/customers/{account}`
- `GET /v1/installations` / `GET /v1/installations/{id}`
- `GET /v1/jobs` / `GET /v1/jobs/{id}`
- `GET /v1/quotes` / `GET /v1/quotes/{id}`
- `GET /v1/calls` / `GET /v1/calls/{id}`

Each resource returns the same business columns shown on the TrackerPro Admin main grid for that module (Customer, Installation, Job, Quote, Call). UI-only computed columns (activity badges, next engineer from diary) and secrets are omitted.

Responses include header `X-TrackerPro-Request-Id` for support.

## Privacy and isolation

- Access tokens do not include database names, servers, or credentials.
- API error responses do not include SQL, connection strings, or stack traces.
- You cannot select another company's data via request parameters.
- Each OAuth client can only read data for the company that issued it.

## Errors

- `401` invalid / expired access token, or revoked client
- `403` missing scope
- `429` rate limited
- OAuth token errors use `error` + `error_description` (safe messages only)

## Usage and logs in Admin

Same page as client setup: **Integrations** > **External API**.

- **OAuth clients** - create, rotate, revoke
- **Usage** - counts by endpoint / day
- **Logs** - recent API calls for support (`X-TrackerPro-Request-Id`)
