# Resolve occupations and classification codes

`GET https://trawle.com/v1/occupations`

Deterministic title aliases, names, slugs or SOC/ISCO code prefixes. Candidates include family slugs usable in JobQuery.families. Occupation slugs and codes are not role filters; resolve role slugs with GET /v1/roles. Unknown input returns an empty list.

## Authentication

- Header `x-api-key`: Read-only API key from https://trawle.com/account#api-keys. 1,000 requests per daily window. Anonymous requests are also supported with a per-IP limit.

## Query parameters

- `q` (string, required): Job title, occupation or classification code. 1 to 100 characters. Example: `senior frontend developer`.
- `limit` (integer, optional): Default `8`. 1 to 20. Example: `8`.

## Responses

### 200: Ranked occupation candidates.

Schema: OccupationLookup

- `items` (array<object>, required, OccupationMatch)
  - `slug` (string, required)
  - `name` (string, required)
  - `family` (object, required)
    - `slug` (string, required)
    - `name` (string, required)
  - `socCode` (string, required): O*NET-SOC 2019 code (classification metadata, not a JobQuery role slug). Example: `15-1252.00`.
  - `iscoCode` (string, required): ISCO-08 unit-group code. Example: `2512`.
  - `match` (string, required): How the input matched: deterministic title alias or a name/code prefix candidate. Confirm ambiguous candidates with the person. One of: `exact`, `phrase`, `prefix`.

### 400: Invalid request: see `error.issues` and `error.hint`.

Schema: Error

- `error` (object, required)
  - `code` (string, required): Machine-readable: `invalid_request`, `not_found`, `forbidden`, `rate_limited`, `internal`. Example: `invalid_request`.
  - `message` (string, required): Example: `places: expected an array of GeoNames ids`.
  - `hint` (string, optional): What to do next, e.g. which lookup to call first. Example: `Resolve place names to ids with GET /v1/places?q=`.
  - `issues` (array<object>, optional): Validation problems, one per invalid field.
    - `path` (string, required)
    - `message` (string, required)

### 401: Invalid, expired or revoked API key.

Schema: Error

- `error` (object, required)
  - `code` (string, required): Machine-readable: `invalid_request`, `not_found`, `forbidden`, `rate_limited`, `internal`. Example: `invalid_request`.
  - `message` (string, required): Example: `places: expected an array of GeoNames ids`.
  - `hint` (string, optional): What to do next, e.g. which lookup to call first. Example: `Resolve place names to ids with GET /v1/places?q=`.
  - `issues` (array<object>, optional): Validation problems, one per invalid field.
    - `path` (string, required)
    - `message` (string, required)

### 429: Rate limit reached. Respect Retry-After and cache results.

Schema: Error

- `error` (object, required)
  - `code` (string, required): Machine-readable: `invalid_request`, `not_found`, `forbidden`, `rate_limited`, `internal`. Example: `invalid_request`.
  - `message` (string, required): Example: `places: expected an array of GeoNames ids`.
  - `hint` (string, optional): What to do next, e.g. which lookup to call first. Example: `Resolve place names to ids with GET /v1/places?q=`.
  - `issues` (array<object>, optional): Validation problems, one per invalid field.
    - `path` (string, required)
    - `message` (string, required)

## Examples

### cURL

```bash
curl "https://trawle.com/v1/occupations?q=senior%20frontend%20developer" \
  -H "x-api-key: $TRAWLE_API_KEY"
```

### TypeScript

```ts
import createClient from "openapi-fetch";

// npx openapi-typescript https://developers.trawle.com/openapi.json -o trawle.d.ts
import type { paths } from "./trawle";

const trawle = createClient<paths>({
  baseUrl: "https://trawle.com",
  headers: { "x-api-key": process.env.TRAWLE_API_KEY },
});

const { data, error } = await trawle.GET("/v1/occupations", {
  params: {
    query: {
      q: "senior frontend developer",
    },
  },
});
```

### Python

```python
import os
import requests

response = requests.get(
    "https://trawle.com/v1/occupations",
    params={
        "q": "senior frontend developer",
    },
    headers={"x-api-key": os.environ["TRAWLE_API_KEY"]},
)
response.raise_for_status()
data = response.json()
```

### Response 200

```json
{
  "items": [
    {
      "slug": "string",
      "name": "string",
      "family": {
        "slug": "string",
        "name": "string"
      },
      "socCode": "15-1252.00",
      "iscoCode": "2512",
      "match": "exact"
    }
  ]
}
```

### Response 400

```json
{
  "error": {
    "code": "invalid_request",
    "message": "query.places.0: Invalid input: expected number, received string",
    "hint": "Fix the fields in `issues`. Ids for `places`, `roles` and `companies` come from the lookup endpoints.",
    "issues": [
      {
        "path": "query.places.0",
        "message": "Invalid input: expected number, received string"
      }
    ]
  }
}
```

### Response 401

```json
{
  "error": {
    "code": "unauthorized",
    "message": "Sign in to use this",
    "hint": "Sign in at /sign-in; requests carry the session cookie."
  }
}
```

### Response 429

```json
{
  "error": {
    "code": "invalid_request",
    "message": "places: expected an array of GeoNames ids",
    "hint": "Resolve place names to ids with GET /v1/places?q=",
    "issues": [
      {
        "path": "string",
        "message": "string"
      }
    ]
  }
}
```
