> ## Documentation Index
> Fetch the complete documentation index at: https://docs.happyuptime.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create data source

Create a new custom JSON API data source. Optionally supply `fields` to create monitoring fields inline. Triggers an immediate fetch in the background.

` POST /data-sources `

Create data source

Create a new custom JSON API data source. Optionally supply `fields` to create monitoring fields inline. Triggers an immediate fetch in the background.

## Servers

- ` https://happyuptime.com/api/v1 `

## Authentication

The operation accepts these alternatives. Schemes within one alternative are required together.

### Alternative 1

- ` bearerAuth `: ` http `

  - HTTP scheme: ` bearer ` (hu_api_key)

  - API key with `hu_` prefix. Send exactly `Authorization: Bearer hu_...`. `X-API-Key` is not supported. Create keys in Dashboard → Settings → API Keys.

## Request body (required)

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` name `, ` url `

  - ` name `: type ` string `

    - minLength: ` 1 `

  - ` description `: type ` unknown `

    - ` anyOf alternative 1 `: type ` string `

    - ` anyOf alternative 2 `: type ` null `

  - ` url `: type ` string `; format ` uri `

  - ` method `: type ` string `

    - enum: ` ["GET","POST"] `

  - ` headers `: type ` unknown `

    - ` anyOf alternative 1 `: type ` object `

    - ` anyOf alternative 2 `: type ` null `

  - ` body `: type ` unknown `

    - ` anyOf alternative 1 `: type ` string `

    - ` anyOf alternative 2 `: type ` null `

  - ` auth_type `: type ` unknown `

    - ` anyOf alternative 1 `: type ` string `

      - enum: ` ["basic","bearer","api_key"] `

    - ` anyOf alternative 2 `: type ` null `

  - ` auth_config `: type ` unknown `

    - ` anyOf alternative 1 `: type ` object `

    - ` anyOf alternative 2 `: type ` null `

  - ` root_path `: type ` unknown `

    - ` anyOf alternative 1 `: type ` string `

    - ` anyOf alternative 2 `: type ` null `

  - ` fetch_interval_s `: type ` integer `

    - minimum: ` 30 `

    - maximum: ` 9007199254740991 `

  - ` timeout_ms `: type ` integer `

    - minimum: ` 1000 `

    - maximum: ` 60000 `

  - ` fields `: type ` array `

    - ` array item `: type ` object `

      - Required fields: ` path `, ` name_template `, ` rule_type `, ` rule_config `

      - ` id `: type ` string `

      - ` path `: type ` string `

      - ` name_template `: type ` string `

      - ` rule_type `: type ` string `

        - enum: ` ["equals","in","diff_lte","truthy","http_ok"] `

      - ` rule_config `: type ` object `

      - ` degraded_rule_config `: type ` unknown `

        - ` anyOf alternative 1 `: type ` object `

        - ` anyOf alternative 2 `: type ` null `

      - ` display_order `: type ` number `

Example:

```json
{
  "name": "My Status API",
  "url": "https://api.example.com/status",
  "method": "GET",
  "fetch_interval_s": 60,
  "fields": [
    {
      "path": "services.*.status",
      "name_template": "{{key}}",
      "rule_type": "equals",
      "rule_config": {
        "value": "ok"
      }
    }
  ]
}
```

## Responses

### ` 201 ` — Data source created

Content type: ` application/json `

- ` value `: type ` object `

  - ` data `: type ` object `

    - ` id `: type ` string `

### ` 400 ` — Validation error

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` error `

  - ` error `: type ` object `

    - Required fields: ` code `, ` message `, ` status `

    - ` code `: type ` string `

      - example: ` "not_found" `

    - ` message `: type ` string `

      - example: ` "Monitor not found" `

    - ` status `: type ` integer `

      - example: ` 404 `

### ` 402 ` — Tier limit reached

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` error `

  - ` error `: type ` object `

    - Required fields: ` code `, ` message `, ` status `

    - ` code `: type ` string `

      - example: ` "not_found" `

    - ` message `: type ` string `

      - example: ` "Monitor not found" `

    - ` status `: type ` integer `

      - example: ` 404 `

## Request examples

### cURL

```curl
curl -X POST 'https://happyuptime.com/api/v1/data-sources' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "My Status API",
  "url": "https://api.example.com/status",
  "method": "GET",
  "fetch_interval_s": 60,
  "fields": [
    {
      "path": "services.*.status",
      "name_template": "{{key}}",
      "rule_type": "equals",
      "rule_config": {
        "value": "ok"
      }
    }
  ]
}'
```

### JavaScript

```javascript
const response = await fetch('https://happyuptime.com/api/v1/data-sources', {
  method: 'POST',
  headers: {
      "Authorization": "Bearer YOUR_API_TOKEN",
      "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "name": "My Status API",
    "url": "https://api.example.com/status",
    "method": "GET",
    "fetch_interval_s": 60,
    "fields": [
      {
        "path": "services.*.status",
        "name_template": "{{key}}",
        "rule_type": "equals",
        "rule_config": {
          "value": "ok"
        }
      }
    ]
  })
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

headers = {
    'Authorization': 'Bearer YOUR_API_TOKEN'
}

response = requests.post('https://happyuptime.com/api/v1/data-sources', headers=headers, json={
  "name": "My Status API",
  "url": "https://api.example.com/status",
  "method": "GET",
  "fetch_interval_s": 60,
  "fields": [
    {
      "path": "services.*.status",
      "name_template": "{{key}}",
      "rule_type": "equals",
      "rule_config": {
        "value": "ok"
      }
    }
  ]
})
print(response.json())
```