# Create ticket

> POST https://api.nabrah.ai/api/ext/omni_v2/ticket

Group: Tickets. Page: https://www.nabrah.ai/en/docs/api-reference/tickets/create-ticket

Creates a new support ticket (conversation) and returns the full ticket object including its server-assigned `id`, inbox, status, priority, and any seeded message. Provide a `subject` and `description`, then identify the customer either by an existing `contact_id` (from GET /api/ext/omni_v2/contact) or by `contact_phone` to look up/create the contact. Optional `agent_id`, `call_id`, and `ticket_type` let you attribute the ticket to a specific agent, link it to a call, and categorize it.

## Identifying the contact

Supply exactly one customer identifier.

- **contact_id (preferred)**: Numeric id of an existing contact. Obtain it from GET /api/ext/omni_v2/contact. Use this when the customer already exists in the project.
- **contact_phone**: E.164 phone number used to resolve (or create) the contact when you do not have a `contact_id`. Useful for inbound channels keyed by phone such as WhatsApp.

## Request fields

- **body fields**: `subject` and `description` form the ticket. `agent_id` attributes it to an AI/human agent, `call_id` links it to a related call record, and `ticket_type` categorizes it (must match a configured ticket type on the inbox). Fields: `subject`, `description`, `agent_id`, `call_id`, `ticket_type`, `contact_id`, `contact_phone`.

## Response

Returns a GetTicketResponse — the same full ticket shape as GET /ticket/{id}. Read `id` from the response to reference the ticket later.

## Authorization

- `X-API-Key` (string, header, required): your workspace API key.

## Body (application/json)

### Example: By contact id

Create a ticket for an existing contact identified by numeric contact_id.

```json
{
  "subject": "Refund request for order #10482",
  "description": "Customer says the item arrived damaged and would like a full refund.",
  "agent_id": "agent_support_01",
  "call_id": "call_8f21 ",
  "ticket_type": "billing",
  "contact_id": 4821
}
```

### Example: By contact phone

Create a ticket and resolve/create the contact from a phone number when you have no contact_id.

```json
{
  "subject": "WhatsApp inquiry about delivery",
  "description": "Customer asked when their order will be delivered.",
  "ticket_type": "support",
  "contact_phone": "+966512345678"
}
```

## Response

### 200 Successful Response

Content type: `application/json`

```json
{
  "account_id": 0,
  "additional_attributes": {},
  "agent_last_seen_at": 0,
  "assignee_last_seen_at": 0,
  "can_reply": false,
  "contact_last_seen_at": 0,
  "created_at": 0,
  "custom_attributes": {},
  "first_reply_created_at": 0,
  "id": 0,
  "inbox_id": 0,
  "labels": [
    "string"
  ],
  "last_activity_at": 0,
  "last_non_activity_message": {
    "account_id": 0,
    "additional_attributes": {},
    "content": "string",
    "content_attributes": {},
    "content_type": "string",
    "conversation": {
      "assignee_id": 0,
      "contact_inbox": {
        "source_id": null
      },
      "last_activity_at": 0,
      "unread_count": 0
    },
    "conversation_id": 0,
    "created_at": 0,
    "external_source_ids": {},
    "id": 0,
    "inbox_id": 0,
    "message_type": 0,
    "private": false,
    "processed_message_content": "string",
    "sender": {
      "availability_status": "string",
      "available_name": "string",
      "avatar_url": "string",
      "id": 0,
      "name": "string",
      "thumbnail": "string",
      "type": "string",
      "additional_attributes": {},
      "blocked": false,
      "created_at": 0,
      "custom_attributes": {},
      "email": "string",
      "identifier": "string",
      "last_activity_at": 0,
      "phone_number": "string"
    },
    "sender_id": 0,
    "sender_type": "string",
    "sentiment": {},
    "source_id": "string",
    "status": "string",
    "updated_at": "string"
  },
  "messages": [
    {
      "account_id": 0,
      "additional_attributes": {},
      "content": "string",
      "content_attributes": {},
      "content_type": "string",
      "conversation": {
        "assignee_id": 0,
        "contact_inbox": null,
        "last_activity_at": 0,
        "unread_count": 0
      },
      "conversation_id": 0,
      "created_at": 0,
      "external_source_ids": {},
      "id": 0,
      "inbox_id": 0,
      "message_type": 0,
      "private": false,
      "processed_message_content": "string",
      "sender": {
        "availability_status": "string",
        "available_name": "string",
        "avatar_url": "string",
        "id": 0,
        "name": "string",
        "thumbnail": "string",
        "type": "string",
        "additional_attributes": {},
        "blocked": false,
        "created_at": 0,
        "custom_attributes": {},
        "email": "string",
        "identifier": "string",
        "last_activity_at": 0,
        "phone_number": "string"
      },
      "sender_id": 0,
      "sender_type": "string",
      "sentiment": {},
      "source_id": "string",
      "status": "string",
      "updated_at": "string"
    }
  ],
  "meta": {
    "channel": "string",
    "hmac_verified": false,
    "sender": {
      "additional_attributes": {},
      "availability_status": "string",
      "blocked": false,
      "created_at": 0,
      "custom_attributes": {},
      "email": "string",
      "id": 0,
      "identifier": "string",
      "last_activity_at": 0,
      "name": "string",
      "phone_number": "string",
      "thumbnail": "string"
    },
    "assignee": {
      "email": "string",
      "available_name": "string",
      "name": "string"
    }
  },
  "muted": false,
  "priority": "string",
  "sla_policy_id": 0,
  "snoozed_until": 0,
  "status": "string",
  "timestamp": 0,
  "unread_count": 0,
  "updated_at": 0
}
```

### 422 Validation Error

Content type: `application/json`

```json
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

## Request examples

### cURL

```bash
curl --request POST \
  --url 'https://api.nabrah.ai/api/ext/omni_v2/ticket' \
  --header 'X-API-Key: <your-api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
  "subject": "Refund request for order #10482",
  "description": "Customer says the item arrived damaged and would like a full refund.",
  "agent_id": "agent_support_01",
  "call_id": "call_8f21 ",
  "ticket_type": "billing",
  "contact_id": 4821
}'
```

### Python

```python
import requests

url = "https://api.nabrah.ai/api/ext/omni_v2/ticket"
headers = {
    "X-API-Key": "<your-api-key>",
}
payload = {
    "subject": "Refund request for order #10482",
    "description": "Customer says the item arrived damaged and would like a full refund.",
    "agent_id": "agent_support_01",
    "call_id": "call_8f21 ",
    "ticket_type": "billing",
    "contact_id": 4821
}

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

### JavaScript

```javascript
const response = await fetch("https://api.nabrah.ai/api/ext/omni_v2/ticket", {
  method: "POST",
  headers: {
    "X-API-Key": "<your-api-key>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "subject": "Refund request for order #10482",
    "description": "Customer says the item arrived damaged and would like a full refund.",
    "agent_id": "agent_support_01",
    "call_id": "call_8f21 ",
    "ticket_type": "billing",
    "contact_id": 4821
  }),
});

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

### Go

```go
package main

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

func main() {
	payload := strings.NewReader(`{
  "subject": "Refund request for order #10482",
  "description": "Customer says the item arrived damaged and would like a full refund.",
  "agent_id": "agent_support_01",
  "call_id": "call_8f21 ",
  "ticket_type": "billing",
  "contact_id": 4821
}`)

	req, _ := http.NewRequest("POST", "https://api.nabrah.ai/api/ext/omni_v2/ticket", payload)
	req.Header.Set("X-API-Key", "<your-api-key>")
	req.Header.Set("Content-Type", "application/json")

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	out, _ := io.ReadAll(res.Body)
	fmt.Println(string(out))
}
```
