> For the complete documentation index, see [llms.txt](https://docs.k9.io/key9-identity/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.k9.io/key9-identity/jsonair/3-using-the-api/3.4-curl-examples.md).

# 3.4 Curl Examples

The examples below assume JSONAir is running at `https://jsonair.example.com`. Replace this with your actual server address.

***

## Step 1 — Get a Bearer Token

```bash
curl -s -X POST https://jsonair.example.com/api/v1/jsonair/auth/token \
  -H "Content-Type: application/json" \
  -d '{"token": "your-plain-text-pat"}'
```

**Response:**

```json
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expires_in": 3600
}
```

Save the `access_token` value for use in the requests below. You can capture it with `jq`:

```bash
TOKEN=$(curl -s -X POST https://jsonair.example.com/api/v1/jsonair/auth/token \
  -H "Content-Type: application/json" \
  -d '{"token": "your-plain-text-pat"}' | jq -r '.access_token')
```

***

## Step 2 — Fetch Configuration Data

Returns the configuration as a Base64-encoded string (default):

```bash
curl -s -X GET https://jsonair.example.com/api/v1/jsonair/config \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "myapp", "name": "prod.yaml", "decode": false}'
```

Have the server decode the Base64 before returning (returns the raw configuration):

```bash
curl -s -X GET https://jsonair.example.com/api/v1/jsonair/config \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "myapp", "name": "prod.yaml", "decode": true}'
```

Or decode locally using `base64`:

```bash
curl -s -X GET https://jsonair.example.com/api/v1/jsonair/config \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "myapp", "name": "prod.yaml"}' | base64 -d
```

***

## Fetch the Reload Key

```bash
curl -s -X GET https://jsonair.example.com/api/v1/jsonair/reload \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "myapp", "name": "prod.yaml"}'
```

**Response:**

```json
{
  "reload": "RELOADKEY"
}
```

***

## Fetch the Debug Level

```bash
curl -s -X GET https://jsonair.example.com/api/v1/jsonair/debug \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "myapp", "name": "prod.yaml"}'
```

**Response:**

```json
{
  "debug": "INFO"
}
```

***

## Handling an Expired Token

When your JWT expires you will receive a `401`. Re-run the auth step to get a new token:

```bash
# Re-authenticate
TOKEN=$(curl -s -X POST https://jsonair.example.com/api/v1/jsonair/auth/token \
  -H "Content-Type: application/json" \
  -d '{"token": "your-plain-text-pat"}' | jq -r '.access_token')

# Retry your request
curl -s -X GET https://jsonair.example.com/api/v1/jsonair/config \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type": "myapp", "name": "prod.yaml", "decode": true}'
```
