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

# Create Task

> Creates a task in the provider's EMR system.

<Info>
  Depending on the EMR system connected to the account, additional fields beyond the base required fields may be required. If a conditionally required field is missing, the API will return a `400` error specifying the missing field.
</Info>

### Request Parameters

#### Required Fields

These fields are always required regardless of the connected EMR:

* **description** (string, required): Task description/body content
* **patient\_mrn** (string, required): Medical Record Number (MRN) of the patient

#### Conditionally Required Fields

Depending on the connected EMR, some combination of the following fields will also be required:

* **subject** (string, conditionally required): Task title/subject line
* **assignee\_user\_id** (string, conditionally required): EMR user ID to assign the task to
* **phone\_call\_type\_id** (string, conditionally required): Identifier for the phone call type
* **notify\_list** (string\[], optional): List of user identifiers to notify about the task. Must be an array of strings if provided.

### Example Requests

<Tabs>
  <Tab title="Example A">
    ```bash theme={null}
    curl -X POST https://api.usecobalt.com/v1/tasks \
    -H 'Content-Type: application/json' \
    -H 'client_id: ci_live_198908HJDKJSH98789OHKJL' \
    -H 'client_secret: cs_live_9827hofdsklOYYHJLJh' \
    -H 'access_token: 493JKLHIU98789hLKH9HHJH' \
    -d '{
        "description": "Schedule patient follow-up appointment to review recent lab results and discuss treatment plan.",
        "patient_mrn": "MRN-12345",
        "subject": "Follow-up appointment needed",
        "assignee_user_id": "74196090-5faa-11e9-9562-e12f6a3ce827"
    }'
    ```
  </Tab>

  <Tab title="Example B">
    ```bash theme={null}
    curl -X POST https://api.usecobalt.com/v1/tasks \
    -H 'Content-Type: application/json' \
    -H 'client_id: ci_live_198908HJDKJSH98789OHKJL' \
    -H 'client_secret: cs_live_9827hofdsklOYYHJLJh' \
    -H 'access_token: 493JKLHIU98789hLKH9HHJH' \
    -d '{
        "description": "Patient called requesting prescription refill for lisinopril 10mg.",
        "patient_mrn": "MRN-67890",
        "phone_call_type_id": "rx_refill",
        "notify_list": ["user_001", "user_002"]
    }'
    ```
  </Tab>
</Tabs>

### Example Response

```json theme={null}
{
    "success": true,
    "message": "Task processing. A webhook event will be sent upon completion.",
    "task_id": "abc123def456789012345678",
    "job_id": 12345
}
```

The response includes:

* **task\_id**: Unique identifier for the created task record
* **job\_id**: Job execution identifier for tracking the async operation

### Error Responses

#### Missing Required Field

If a required or conditionally required field is missing, the API returns a `400` with the specific field name:

```json theme={null}
{
    "success": false,
    "message": "Missing required field: description"
}
```

#### User Not Found

```json theme={null}
{
    "success": false,
    "message": "User not found."
}
```

### Webhook Notifications

When the task processing is complete, we will send a webhook to your registered endpoint. Here are examples of what those webhook payloads will look like:

#### Success

```json theme={null}
{
    "id": "evt_1J9X2q2eZvKYlo2CluR9g9gV",
    "access_token_reference_id": "user_1J9X2q2eZvKYlo2Cxyz",
    "object": "event",
    "created": "2025-10-09T10:30:00Z",
    "type": "task.created",
    "job_id": "12345",
    "data": {
        "task_id": "abc123def456789012345678",
        "emr_task_id": "task_emr_internal_id",
        "subject": "Follow-up appointment needed",
        "description": "Schedule patient follow-up appointment to review recent lab results and discuss treatment plan.",
        "assignee_user_id": "74196090-5faa-11e9-9562-e12f6a3ce827",
        "patient_mrn": "MRN-12345"
    }
}
```

#### Failure

```json theme={null}
{
    "id": "evt_1J9X2q2eZvKYlo2CluR9g9gW",
    "access_token_reference_id": "user_1J9X2q2eZvKYlo2Cxyz",
    "object": "event",
    "created": "2025-10-09T10:35:00Z",
    "type": "task.failed",
    "job_id": "12345",
    "data": {
        "task_id": "abc123def456789012345678",
        "failure_reason": "Failed to create task"
    }
}
```


## OpenAPI

````yaml POST /tasks
openapi: 3.0.0
info:
  title: Cobalt API
  version: 1.0.1
  description: API for interacting with Cobalt's EHR integration services
servers:
  - url: https://api.usecobalt.com/v1
security:
  - ClientCredentials: []
    ClientSecret: []
    AccessToken: []
paths:
  /tasks:
    post:
      summary: Create Task
      description: >-
        Creates a task in the provider's EMR using RPA via a headless browser.
        This is an asynchronous operation that returns immediately with a
        job_id, and sends webhook notification upon completion.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - description
                - patient_mrn
              properties:
                description:
                  type: string
                  description: Task description/body content
                patient_mrn:
                  type: string
                  description: Medical Record Number (MRN) of the patient
                subject:
                  type: string
                  description: >-
                    Task title/subject line. Conditionally required depending on
                    the connected EMR.
                assignee_user_id:
                  type: string
                  description: >-
                    EMR user ID to assign the task to. Conditionally required
                    depending on the connected EMR.
                phone_call_type_id:
                  type: string
                  description: >-
                    Identifier for the phone call type. Conditionally required
                    depending on the connected EMR.
                notify_list:
                  type: array
                  items:
                    type: string
                  description: List of user identifiers to notify about the task. Optional.
      responses:
        '200':
          description: Task queued successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                  task_id:
                    type: string
                    description: Unique identifier for the created task record
                  job_id:
                    type: integer
                    description: Job execution identifier for tracking the async operation
        '400':
          description: Bad request - Missing or invalid parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
        '404':
          description: User not found or Patient not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
                    example: User not found.
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
components:
  securitySchemes:
    ClientCredentials:
      type: apiKey
      in: header
      name: client_id
    ClientSecret:
      type: apiKey
      in: header
      name: client_secret
    AccessToken:
      type: apiKey
      in: header
      name: access_token

````