> 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 or update a contact by phone number

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

Updates the contact that has the phone number, or creates one if the account has none. The API changes only the fields that you send. `custom_attributes` and `additional_attributes` merge into the stored values. Each value in `notes` adds a note. The API does the whole request as 1 unit: if a field is not valid, it changes nothing.


Reference: https://docs.hams.ai/omni-channel/reference/contacts/create-or-update-contact-by-phone

## 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 ContactByPhoneRequest.

- `phone_number` (string, required) — The phone number in E.164 format. It identifies the contact.
- `name` (string, optional)
- `email` (string, optional)
- `identifier` (string, optional)
- `blocked` (boolean, optional)
- `avatar_url` (string, optional) — The URL of an image. The API downloads it in the background as the avatar.
- `notes` (list of string, optional) — Each value adds a note to the contact. A blank value is not valid.
- `custom_attributes` (map from string to any, optional)
- `additional_attributes` (map from string to any, optional)

## Response

### 200

The API updated a contact. `created` is `false`.

- `payload` (ContactWithNotes, optional) — A contact, without `contact_inboxes`, with its 10 newest notes.
- `created` (boolean, optional) — `true` if the API created the contact.

### 201

The API created a contact. `created` is `true`.

- `payload` (ContactWithNotes, optional) — A contact, without `contact_inboxes`, with its 10 newest notes.
- `created` (boolean, optional) — `true` if the API created the contact.

## 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`.

### 422 Unprocessable Entity Error

`error` is `phone_number_required`, `invalid_phone_number`, or `validation_failed`. A field that is not valid, for example an email address that another contact has, or a blank note, gives `validation_failed`.

- `error` (string, required) — A stable code for a program, for example `outside_messaging_window`. Branch on this field.
- `message` (string, required) — A message for a person. It can change at any time.

## Types

### ContactWithNotes

A contact, without `contact_inboxes`, with its 10 newest notes.

- `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.
- `notes` (list of ContactNote, optional) — The 10 newest notes, newest first.

### ContactNote

- `id` (integer, optional)
- `content` (string, optional)
- `created_at` (integer, optional) — Unix timestamp, in seconds.

## Examples

### Example 1

**Request**

```json
{
  "phone_number": "string"
}
```

**Response**

```json
{
  "payload": {
    "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": [
      {}
    ],
    "notes": [
      {
        "id": 1,
        "content": "string",
        "created_at": 1
      }
    ]
  },
  "created": true
}
```

**SDK Code**

```python
import requests

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

payload = { "phone_number": "string" }
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/contacts/create_or_update';
const options = {
  method: 'POST',
  headers: {api_access_token: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"phone_number":"string"}'
};

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/contacts/create_or_update"

	payload := strings.NewReader("{\n  \"phone_number\": \"string\"\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/contacts/create_or_update")

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  \"phone_number\": \"string\"\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/contacts/create_or_update")
  .header("api_access_token", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"phone_number\": \"string\"\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/contacts/create_or_update', [
  'body' => '{
  "phone_number": "string"
}',
  '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/contacts/create_or_update");
var request = new RestRequest(Method.POST);
request.AddHeader("api_access_token", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"phone_number\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "api_access_token": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["phone_number": "string"] 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/contacts/create_or_update")! 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()
```

### Example 2

**Request**

```json
{
  "phone_number": "string"
}
```

**Response**

```json
{
  "payload": {
    "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": [
      {}
    ],
    "notes": [
      {
        "id": 1,
        "content": "string",
        "created_at": 1
      }
    ]
  },
  "created": true
}
```

**SDK Code**

```python
import requests

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

payload = { "phone_number": "string" }
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/contacts/create_or_update';
const options = {
  method: 'POST',
  headers: {api_access_token: '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"phone_number":"string"}'
};

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/contacts/create_or_update"

	payload := strings.NewReader("{\n  \"phone_number\": \"string\"\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/contacts/create_or_update")

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  \"phone_number\": \"string\"\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/contacts/create_or_update")
  .header("api_access_token", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"phone_number\": \"string\"\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/contacts/create_or_update', [
  'body' => '{
  "phone_number": "string"
}',
  '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/contacts/create_or_update");
var request = new RestRequest(Method.POST);
request.AddHeader("api_access_token", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"phone_number\": \"string\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "api_access_token": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["phone_number": "string"] 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/contacts/create_or_update")! 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()
```