> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.joincandidhealth.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.joincandidhealth.com/_mcp/server.

# Create a custom schema

POST https://api.joincandidhealth.com/api/custom-schemas/v1
Content-Type: application/json

Create custom schema with a set of typed keys. Schema keys can be referenced as inputs in user-configurable rules in the Rules
Engine, and key-value pairs can be attached to claims via the Encounters API.

Reference: https://docs.joincandidhealth.com/api-reference/custom-schemas/v-1/create

## Authentication

- OAuth2 — send the obtained token as `Authorization: Bearer <token>`

## Servers

- `https://api.joincandidhealth.com` (Production, default)
- `https://api-staging.joincandidhealth.com` (Staging)
- `https://sandbox-api.joincandidhealth.com` (CandidSandbox)
- `https://staging-api.joincandidhealth.com` (CandidStaging)
- `http://localhost:5050` (Local)

## Request

### Body (application/json)

This endpoint expects an object.

- `name` (string, required)
- `fields` (list of SchemaField, required)
- `description` (string, optional)

## Response

### 200

- `id` (UUID, required)
- `name` (string, required)
- `fields` (list of SchemaField, required)
- `description` (string, optional)

## Errors

### 422 Schema Validation HTTP Failure

- `errorName` ("SchemaValidationHttpFailure", required)
- `content` (SchemaValidationFailure, required)

## Types

### SchemaField

- `key` (string, required)
- `type` (enum, required) — The BOOLEAN and STRING primitives respectively map to the `boolean` and `string` JSON data types. The DOUBLE and INTEGER primitives must be written as a JSON `number` type.
  - Allowed values: `BOOLEAN`, `DOUBLE`, `INTEGER`, `STRING`

### SchemaValidationFailure

- `errors` (list of SchemaValidationError, required)

### SchemaValidationError

- `type`: `schema_name_already_exists`
  - `id` (UUID, required)
  - `name` (string, required)
- `type`: `key_name_already_exists`
  - `key` (string, required)
  - `value_type` (enum, required) — The BOOLEAN and STRING primitives respectively map to the `boolean` and `string` JSON data types. The DOUBLE and INTEGER primitives must be written as a JSON `number` type.
    - Allowed values: `BOOLEAN`, `DOUBLE`, `INTEGER`, `STRING`

## Examples

**Request**

```json
{
  "name": "General Medicine",
  "fields": [
    {
      "key": "provider_category",
      "type": "STRING"
    },
    {
      "key": "is_urgent_care",
      "type": "BOOLEAN"
    },
    {
      "key": "bmi",
      "type": "DOUBLE"
    },
    {
      "key": "age",
      "type": "INTEGER"
    }
  ],
  "description": "Values associated with a generic visit"
}
```

**Response**

```json
{
  "id": "ec096b13-f80a-471d-aaeb-54b021c9d582",
  "name": "General Medicine",
  "fields": [
    {
      "key": "provider_category",
      "type": "STRING"
    },
    {
      "key": "is_urgent_care",
      "type": "BOOLEAN"
    },
    {
      "key": "bmi",
      "type": "DOUBLE"
    },
    {
      "key": "age",
      "type": "INTEGER"
    }
  ],
  "description": "Values associated with a generic visit"
}
```

**SDK Code**

```python
import requests

url = "https://api.joincandidhealth.com/api/custom-schemas/v1"

payload = {
    "name": "General Medicine",
    "fields": [
        {
            "key": "provider_category",
            "type": "STRING"
        },
        {
            "key": "is_urgent_care",
            "type": "BOOLEAN"
        },
        {
            "key": "bmi",
            "type": "DOUBLE"
        },
        {
            "key": "age",
            "type": "INTEGER"
        }
    ],
    "description": "Values associated with a generic visit"
}
headers = {
    "Authorization": "<token>.",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.joincandidhealth.com/api/custom-schemas/v1';
const options = {
  method: 'POST',
  headers: {Authorization: '<token>.', 'Content-Type': 'application/json'},
  body: '{"name":"General Medicine","fields":[{"key":"provider_category","type":"STRING"},{"key":"is_urgent_care","type":"BOOLEAN"},{"key":"bmi","type":"DOUBLE"},{"key":"age","type":"INTEGER"}],"description":"Values associated with a generic visit"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.joincandidhealth.com/api/custom-schemas/v1"

	payload := strings.NewReader("{\n  \"name\": \"General Medicine\",\n  \"fields\": [\n    {\n      \"key\": \"provider_category\",\n      \"type\": \"STRING\"\n    },\n    {\n      \"key\": \"is_urgent_care\",\n      \"type\": \"BOOLEAN\"\n    },\n    {\n      \"key\": \"bmi\",\n      \"type\": \"DOUBLE\"\n    },\n    {\n      \"key\": \"age\",\n      \"type\": \"INTEGER\"\n    }\n  ],\n  \"description\": \"Values associated with a generic visit\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "<token>.")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.joincandidhealth.com/api/custom-schemas/v1")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = '<token>.'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"General Medicine\",\n  \"fields\": [\n    {\n      \"key\": \"provider_category\",\n      \"type\": \"STRING\"\n    },\n    {\n      \"key\": \"is_urgent_care\",\n      \"type\": \"BOOLEAN\"\n    },\n    {\n      \"key\": \"bmi\",\n      \"type\": \"DOUBLE\"\n    },\n    {\n      \"key\": \"age\",\n      \"type\": \"INTEGER\"\n    }\n  ],\n  \"description\": \"Values associated with a generic visit\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.joincandidhealth.com/api/custom-schemas/v1")
  .header("Authorization", "<token>.")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"General Medicine\",\n  \"fields\": [\n    {\n      \"key\": \"provider_category\",\n      \"type\": \"STRING\"\n    },\n    {\n      \"key\": \"is_urgent_care\",\n      \"type\": \"BOOLEAN\"\n    },\n    {\n      \"key\": \"bmi\",\n      \"type\": \"DOUBLE\"\n    },\n    {\n      \"key\": \"age\",\n      \"type\": \"INTEGER\"\n    }\n  ],\n  \"description\": \"Values associated with a generic visit\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.joincandidhealth.com/api/custom-schemas/v1', [
  'body' => '{
  "name": "General Medicine",
  "fields": [
    {
      "key": "provider_category",
      "type": "STRING"
    },
    {
      "key": "is_urgent_care",
      "type": "BOOLEAN"
    },
    {
      "key": "bmi",
      "type": "DOUBLE"
    },
    {
      "key": "age",
      "type": "INTEGER"
    }
  ],
  "description": "Values associated with a generic visit"
}',
  'headers' => [
    'Authorization' => '<token>.',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.joincandidhealth.com/api/custom-schemas/v1");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "<token>.");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"General Medicine\",\n  \"fields\": [\n    {\n      \"key\": \"provider_category\",\n      \"type\": \"STRING\"\n    },\n    {\n      \"key\": \"is_urgent_care\",\n      \"type\": \"BOOLEAN\"\n    },\n    {\n      \"key\": \"bmi\",\n      \"type\": \"DOUBLE\"\n    },\n    {\n      \"key\": \"age\",\n      \"type\": \"INTEGER\"\n    }\n  ],\n  \"description\": \"Values associated with a generic visit\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "<token>.",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "General Medicine",
  "fields": [
    [
      "key": "provider_category",
      "type": "STRING"
    ],
    [
      "key": "is_urgent_care",
      "type": "BOOLEAN"
    ],
    [
      "key": "bmi",
      "type": "DOUBLE"
    ],
    [
      "key": "age",
      "type": "INTEGER"
    ]
  ],
  "description": "Values associated with a generic visit"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.joincandidhealth.com/api/custom-schemas/v1")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```