# 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}'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.k9.io/key9-identity/jsonair/3-using-the-api/3.4-curl-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
