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

# Get pre-call context

GET https://omni-channel.hams.ai/api/v1/accounts/{account_id}/developer/precall_context

Returns the contact, the latest conversation, the recent messages, and a text summary of a customer as 1 flat map of strings. An external voice agent can use each key as a template variable. Give 1 of `conversation_id`, `contact_id`, or `phone_number`. If the request has more than 1, the API reads them in that order. The endpoint only reads data.


Reference: https://docs.hams.ai/omni-channel/reference/pre-call-context/get-precall-context

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

### Query parameters

- `conversation_id` (integer, optional) — The conversation number in the dashboard URL (`display_id`).
- `contact_id` (integer, optional) — The id of the contact. The API uses the conversation of the contact with the most recent activity, in any inbox.
- `phone_number` (string, optional) — The phone number of the contact in E.164 format. The API adds the `+` if it is not there. The API uses the conversation of the contact with the most recent activity.

## Response

### 200

The context of the customer.

- `contact_id` (string, optional)
- `contact_name` (string, optional)
- `contact_email` (string, optional)
- `contact_phone_number` (string, optional)
- `contact_identifier` (string, optional)
- `contact_contact_type` (string, optional) — `visitor`, `lead`, or `customer`.
- `conversation_id` (string, optional) — The internal `id` of the conversation. It is not the number in the dashboard URL. The other developer endpoints take `conversation_display_id`.
- `conversation_display_id` (string, optional) — The conversation number in the dashboard URL.
- `conversation_inbox_id` (string, optional)
- `conversation_contact_id` (string, optional)
- `conversation_status` (string, optional)
- `conversation_priority` (string, optional)
- `conversation_label_list` (string, optional) — The labels, with a comma and a space between them.
- `messages` (string, optional) — 1 line for each public message, oldest first, with the prefix `user:` or `assistant:`. The last 100 messages, up to 40,000 characters. Empty when there is no conversation.
- `summary` (string, optional) — The same context as a Markdown text, for the prompt of a voice agent.

## 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, contact, inbox, or phone number is not in this account. `error` is `not_found`.

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

### 422 Unprocessable Entity Error

The request has no identifier (`identifier_required`), or the phone number is not in E.164 format (`invalid_phone_number`).

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

## Examples

**Response**

```json
{
  "contact_id": "42",
  "contact_name": "Katherine Johnson",
  "contact_email": "katherine@example.com",
  "contact_phone_number": "+971500000000",
  "contact_identifier": "cust_9931",
  "contact_contact_type": "customer",
  "conversation_id": "5821",
  "conversation_display_id": "1234",
  "conversation_inbox_id": "5",
  "conversation_contact_id": "42",
  "conversation_status": "open",
  "conversation_priority": "",
  "conversation_label_list": "vip, refund",
  "messages": "user: Where is my order?\nassistant: It is on its way.",
  "summary": "# Current Conversation Context\n- Conversation ID: 1234\n...",
  "contact_custom_attributes_plan": "pro"
}
```

**SDK Code**

```python
import requests

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

querystring = {"phone_number":"+971500000000"}

headers = {"api_access_token": "<apiKey>"}

response = requests.get(url, headers=headers, params=querystring)

print(response.json())
```

```javascript
const url = 'https://omni-channel.hams.ai/api/v1/accounts/1/developer/precall_context?phone_number=%2B971500000000';
const options = {method: 'GET', headers: {api_access_token: '<apiKey>'}};

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"
	"net/http"
	"io"
)

func main() {

	url := "https://omni-channel.hams.ai/api/v1/accounts/1/developer/precall_context?phone_number=%2B971500000000"

	req, _ := http.NewRequest("GET", url, nil)

	req.Header.Add("api_access_token", "<apiKey>")

	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/precall_context?phone_number=%2B971500000000")

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

request = Net::HTTP::Get.new(url)
request["api_access_token"] = '<apiKey>'

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.get("https://omni-channel.hams.ai/api/v1/accounts/1/developer/precall_context?phone_number=%2B971500000000")
  .header("api_access_token", "<apiKey>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('GET', 'https://omni-channel.hams.ai/api/v1/accounts/1/developer/precall_context?phone_number=%2B971500000000', [
  'headers' => [
    'api_access_token' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://omni-channel.hams.ai/api/v1/accounts/1/developer/precall_context?phone_number=%2B971500000000");
var request = new RestRequest(Method.GET);
request.AddHeader("api_access_token", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["api_access_token": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://omni-channel.hams.ai/api/v1/accounts/1/developer/precall_context?phone_number=%2B971500000000")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

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()
```