Source: https://leadping.ai/docs/api-reference/appointments/create-an-appointment

# Create an appointment.

Schedules a callback appointment for a lead and configures its assigned agent and reminder.

## Endpoint

```http
POST https://api.leadping.ai/appointments
```

## Authorizations

### Authorization

`string` · `header` · **required**

Authorization header using the Bearer scheme. Accepted values are Leadping user JWT access tokens and WorkOS organization API keys beginning with `sk_`.

## Request body

**Content types:**

- `application/json`
- `text/json`
- `application/*+json`

The appointment details to create.

Creates or reschedules an agent's callback appointment.

| Field | Type | Required | Constraints |
|---|---|---:|---|
| `title` | `string` | Yes | Maximum string length: `200` |
| `leadId` | `string` | Yes |  |
| `timeZoneId` | `string` | Yes |  |
| `assignedToUserId` | `null \| string` | No |  |
| `startAt` | `string<date-time>` | No |  |
| `notes` | `null \| string` | No | Maximum string length: `2000` |
| `expectedRevision` | `integer<int64>` | No |  |

### Example request

```json
{
  "title": "<string>",
  "leadId": "<string>",
  "timeZoneId": "<string>",
  "assignedToUserId": "<string>",
  "startAt": "2023-11-07T05:31:56Z",
  "notes": "<string>",
  "expectedRevision": 123
}
```

## Code examples

### cURL

```bash
curl --request POST \
  --url https://api.leadping.ai/appointments \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "title": "<string>",
  "leadId": "<string>",
  "timeZoneId": "<string>"
}'
```

### Python

```python
import requests

url = "https://api.leadping.ai/appointments"

payload = {
    "title": "<string>",
    "leadId": "<string>",
    "timeZoneId": "<string>"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://api.leadping.ai/appointments");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Authorization", "Bearer <token>");
request.AddJsonBody("{\n  \"title\": \"<string>\",\n  \"leadId\": \"<string>\",\n  \"timeZoneId\": \"<string>\"\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://api.leadping.ai/appointments")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"title\": \"<string>\",\n  \"leadId\": \"<string>\",\n  \"timeZoneId\": \"<string>\"\n}")
  .asString();
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({title: '<string>', leadId: '<string>', timeZoneId: '<string>'})
};

fetch('https://api.leadping.ai/appointments', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Go

```go
package main

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

func main() {

	url := "https://api.leadping.ai/appointments"

	payload := strings.NewReader("{\n  \"title\": \"<string>\",\n  \"leadId\": \"<string>\",\n  \"timeZoneId\": \"<string>\"\n}")

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

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

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

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

	fmt.Println(string(body))

}
```

### PHP

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.leadping.ai/appointments",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'title' => '<string>',
    'leadId' => '<string>',
    'timeZoneId' => '<string>'
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

## Response

### `200 OK`

**Content type:** `text/plain`

An appointment visible to the current user, with history populated on detail requests.

```json
{
  "isDemo": true,
  "createdAt": "2023-11-07T05:31:56Z",
  "modifiedAt": "2023-11-07T05:31:56Z",
  "history": [
    {
      "revision": 123,
      "type": "<string>",
      "at": "2023-11-07T05:31:56Z",
      "actorId": "<string>",
      "actorName": "<string>",
      "startAt": "2023-11-07T05:31:56Z",
      "reminderAt": "2023-11-07T05:31:56Z",
      "assignedToName": "<string>",
      "title": "<string>",
      "notes": "<string>"
    }
  ],
  "id": "<string>",
  "leadId": "<string>",
  "leadFirstName": "<string>",
  "leadLastName": "<string>",
  "leadEmail": "jsmith@example.com",
  "leadAvatarUrl": "<string>",
  "leadName": "<string>",
  "organizationId": "<string>",
  "organizationName": "<string>",
  "assignedToUserId": "<string>",
  "assignedToName": "<string>",
  "startAt": "2023-11-07T05:31:56Z",
  "timeZoneId": "<string>",
  "title": "<string>",
  "notes": "<string>",
  "status": "<string>",
  "revision": 123,
  "reminderAt": "2023-11-07T05:31:56Z",
  "dismissedAt": "2023-11-07T05:31:56Z"
}
```

#### Response fields

| Field | Type |
|---|---|
| `isDemo` | `boolean` |
| `createdAt` | `null \| string<date-time>` |
| `modifiedAt` | `null \| string<date-time>` |
| `history` | `object[]` |
| `id` | `string` |
| `leadId` | `string` |
| `leadFirstName` | `null \| string` |
| `leadLastName` | `null \| string` |
| `leadEmail` | `null \| string<email>` |
| `leadAvatarUrl` | `null \| string<uri>` |
| `leadName` | `string` |
| `organizationId` | `string` |
| `organizationName` | `null \| string` |
| `assignedToUserId` | `string` |
| `assignedToName` | `string` |
| `startAt` | `string<date-time>` |
| `timeZoneId` | `string` |
| `title` | `string` |
| `notes` | `null \| string` |
| `status` | `string` |
| `revision` | `integer<int64>` |
| `reminderAt` | `string<date-time>` |
| `dismissedAt` | `null \| string<date-time>` |

### `history` item fields

`history` contains immutable snapshots of appointment changes and their actors.

| Field | Type |
|---|---|
| `revision` | `integer<int64>` |
| `type` | `string` |
| `at` | `string<date-time>` |
| `actorId` | `null \| string` |
| `actorName` | `null \| string` |
| `startAt` | `string<date-time>` |
| `reminderAt` | `string<date-time>` |
| `assignedToName` | `string` |
| `title` | `string` |
| `notes` | `null \| string` |

## Errors

Error responses use `application/problem+json`.

### `401 Unauthorized`

Authentication credentials are missing or invalid.

```json
{
  "type": "about:blank",
  "title": "Unauthorized",
  "status": 401,
  "detail": "The request could not be completed."
}
```

Response header:

- `WWW-Authenticate`: Bearer authentication challenge returned when credentials are missing or invalid.

### `403 Forbidden`

The caller does not have permission to perform this operation.

```json
{
  "type": "about:blank",
  "title": "Forbidden",
  "status": 403,
  "detail": "The request could not be completed."
}
```

### `429 Too Many Requests`

The API rate limit for this account or client has been exceeded.

```json
{
  "type": "about:blank",
  "title": "Too Many Requests",
  "status": 429,
  "detail": "The request could not be completed."
}
```

Response header:

- `Retry-After`: Number of seconds to wait before retrying the request.

### Problem-details fields

| Field | Type | Description |
|---|---|---|
| `type` | `null \| string` | URI reference that identifies the problem type. |
| `title` | `null \| string` | Short, human-readable summary of the problem. |
| `status` | `null \| integer<int32>` | HTTP status code returned for the problem. |
| `detail` | `null \| string` | Human-readable explanation specific to this occurrence of the problem. |
| `instance` | `null \| string` | URI reference that identifies this specific occurrence of the problem. |
| `errors` | `object` | Validation errors keyed by the JSON request field name. Present for request validation failures. |
| `traceId` | `string` | Request trace identifier used to correlate this problem with Leadping diagnostics. |

## Navigation

- Previous: [List appointments.](https://leadping.ai/docs/api-reference/appointments/list-appointments)
- Next: [Complete an appointment.](https://leadping.ai/docs/api-reference/appointments/complete-an-appointment)
