> This page is for Omni Channel.

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

# Create a conversation

POST https://omni-channel.hams.ai/api/v1/accounts/{account_id}/developer/conversations
Content-Type: application/json

Creates a conversation for a contact on an inbox. If the inbox keeps 1 conversation for each contact, the API returns the latest conversation of the contact instead. This endpoint does not check the service window for `message`. For most integrations, `POST /accounts/{account_id}/developer/messages` is better.

Reference: https://docs.hams.ai/omni-channel/reference/conversations/create-conversation

## Authentication

- `api_access_token` header (required) — An API key that an administrator creates in **Settings** > **Developer**. The personal access token of a user does not work. A key reaches every inbox, conversation, and contact in the account that created it, and nothing in other accounts.

## Request

### Path parameters

- `account_id` (integer, required) — The id of your account. It is the number after `/accounts/` in the dashboard URL.

### Body (application/json)

This endpoint expects a CreateConversationRequest.

- `inbox_id` (integer, required) — The inbox of the conversation.
- `contact_id` (integer, required) — The contact of the conversation.
- `message` (CreateConversationRequestMessage, optional) — An optional first message.
- `status` (enum, optional)
  - Allowed values: `open`, `resolved`, `pending`, `snoozed`
- `assignee_id` (integer, optional) — An agent of the account. An id from another account returns `404`.
- `team_id` (integer, optional) — A team of the account. An id from another account returns `404`.
- `custom_attributes` (map from string to any, optional)
- `additional_attributes` (map from string to any, optional)
- `snoozed_until` (integer, optional) — For `snoozed`, a Unix timestamp in seconds.

## Response

### 200

The conversation.

- `id` (integer, optional) — The conversation number in the dashboard URL (`display_id`). It is not the internal `id`.
- `account_id` (integer, optional)
- `inbox_id` (integer, optional)
- `uuid` (string, optional)
- `status` (enum, optional)
  - Allowed values: `open`, `resolved`, `pending`, `snoozed`
- `can_reply` (boolean, optional) — `true` when the service window is open and the API accepts plain `content`. When `false`, send a template.
- `priority` (enum, optional)
  - Allowed values: `urgent`, `high`, `medium`, `low`
- `labels` (list of string, optional)
- `custom_attributes` (map from string to any, optional)
- `additional_attributes` (map from string to any, optional)
- `snoozed_until` (string, optional, nullable) — The time when a snoozed conversation opens again.
- `muted` (boolean, optional)
- `unread_count` (integer, optional)
- `created_at` (integer, optional) — Unix timestamp, in seconds.
- `last_activity_at` (integer, optional) — Unix timestamp, in seconds.
- `waiting_since` (integer, optional) — Unix timestamp, in seconds. `0` when the conversation does not wait for a reply.
- `messages` (list of map from string to any, optional) — A list with the last message of the conversation.
- `meta` (ConversationMeta, optional) — The contact, the channel, the agent, and the team of the conversation.

## Errors

### 401 Unauthorized Error

The token does not exist, is not an API key, or belongs to another account. The token can also be the token of a user who is not a member of the account, or the account can be suspended. The body has only the `error` field.

- `error` (string, required) — `Invalid Access Token`, `Key is not authorized to access this account`, `Access to this endpoint is not authorized for this token`, `You are not authorized to access this account`, or `Account is suspended`.

### 404 Not Found Error

The conversation or contact is not in this account. The body is `{"error": "Resource could not be found"}`.

- `error` (string, required)

### 422 Unprocessable Entity Error

A field is not valid, for example an email address that another contact has.

- `message` (string, required) — The problems, with a comma between them. For example `Email has already been taken`.
- `attributes` (list of string, required) — The names of the fields that are not valid.

## Types

### CreateConversationRequestMessage

An optional first message.

- `content` (string, optional)

### ConversationMeta

The contact, the channel, the agent, and the team of the conversation.

- `sender` (Contact, optional)
- `channel` (string, optional) — The channel type of the inbox, for example `Channel::Whatsapp`.
- `assignee` (map from string to any, optional) — The agent or the AI agent that owns the conversation.
- `assignee_type` (enum, optional) — `User` for an agent, `Hams::Agent::Assistant` for an AI agent, or `AgentBot` for another bot. A conversation that an AI agent or a bot owns counts as assigned.
  - Allowed values: `User`, `Hams::Agent::Assistant`, `AgentBot`
- `team` (map from string to any, optional)
- `hmac_verified` (boolean, optional, nullable)

### Contact

- `id` (integer, optional)
- `name` (string, optional)
- `email` (string, optional, nullable)
- `phone_number` (string, optional, nullable) — E.164, for example `+971500000000`.
- `identifier` (string, optional, nullable) — Your own id for the contact. It is unique in the account.
- `blocked` (boolean, optional)
- `availability_status` (string, optional)
- `thumbnail` (string, optional)
- `custom_attributes` (map from string to any, optional)
- `additional_attributes` (map from string to any, optional)
- `last_activity_at` (integer, optional) — Unix timestamp, in seconds.
- `created_at` (integer, optional) — Unix timestamp, in seconds.
- `contact_inboxes` (list of map from string to any, optional) — The inboxes where the contact has an address.

## Examples

**Request**

```json
{
  "inbox_id": 1,
  "contact_id": 1
}
```

**Response**

```json
{
  "id": 1,
  "account_id": 1,
  "inbox_id": 1,
  "uuid": "string",
  "status": "open",
  "can_reply": true,
  "priority": "urgent",
  "labels": [
    "string"
  ],
  "custom_attributes": {},
  "additional_attributes": {},
  "snoozed_until": "string",
  "muted": true,
  "unread_count": 1,
  "created_at": 1,
  "last_activity_at": 1,
  "waiting_since": 1,
  "messages": [
    {}
  ],
  "meta": {
    "sender": {
      "id": 1,
      "name": "string",
      "email": "string",
      "phone_number": "string",
      "identifier": "string",
      "blocked": true,
      "availability_status": "string",
      "thumbnail": "string",
      "custom_attributes": {},
      "additional_attributes": {},
      "last_activity_at": 1,
      "created_at": 1,
      "contact_inboxes": [
        {}
      ]
    },
    "channel": "string",
    "assignee": {},
    "assignee_type": "User",
    "team": {},
    "hmac_verified": true
  }
}
```

**SDK Code**

```python
import requests

url = "https://omni-channel.hams.ai/api/v1/accounts/1/developer/conversations"

payload = {
    "inbox_id": 1,
    "contact_id": 1
}
headers = {
    "api_access_token": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://omni-channel.hams.ai/api/v1/accounts/1/developer/conversations';
const options = {
  method: 'POST',
  headers: {api_access_token: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"inbox_id":1,"contact_id":1}'
};

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://omni-channel.hams.ai/api/v1/accounts/1/developer/conversations"

	payload := strings.NewReader("{\n  \"inbox_id\": 1,\n  \"contact_id\": 1\n}")

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

	req.Header.Add("api_access_token", "<apiKey>")
	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://omni-channel.hams.ai/api/v1/accounts/1/developer/conversations")

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

request = Net::HTTP::Post.new(url)
request["api_access_token"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"inbox_id\": 1,\n  \"contact_id\": 1\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://omni-channel.hams.ai/api/v1/accounts/1/developer/conversations")
  .header("api_access_token", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"inbox_id\": 1,\n  \"contact_id\": 1\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://omni-channel.hams.ai/api/v1/accounts/1/developer/conversations', [
  'body' => '{
  "inbox_id": 1,
  "contact_id": 1
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'api_access_token' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://omni-channel.hams.ai/api/v1/accounts/1/developer/conversations");
var request = new RestRequest(Method.POST);
request.AddHeader("api_access_token", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"inbox_id\": 1,\n  \"contact_id\": 1\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "api_access_token": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "inbox_id": 1,
  "contact_id": 1
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://omni-channel.hams.ai/api/v1/accounts/1/developer/conversations")! 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()
```