# Search contacts

> GET https://api.nabrah.ai/api/ext/omni_v2/contact/search

Group: Contacts. Page: https://www.nabrah.ai/en/docs/api-reference/contacts/search-contacts

Searches contacts in the project the API key is scoped to and returns a paginated list of matches. Pass the search text in the `q` query parameter to match against contact fields such as name, email, and phone number. Results follow the same shape as the list endpoint — a `meta` block with `count` and `current_page` plus a `payload` array of contacts — and can be ordered with `sort` and paged with `page`.

## Authentication

- **X-API-Key header**: Send your Web API key (prefix `nb_`) in the `X-API-Key` header. The key is scoped to one project, so only that project's contacts are searched.

## Searching and paging

Combine q, sort, and page to find and walk through matches.

- **Query (q)**: Provide the search text in `q`. The search matches against contact fields such as name, email, and phone number. Omitting `q` returns contacts unfiltered (subject to sort and paging). Only existing contacts are found: a number that has never written to you and was never added as a contact returns no results.
- **Pagination**: The response `meta.count` reports the total number of matches and `meta.current_page` the page returned. Pass `?page=1`, `?page=2`, and so on, incrementing until the `payload` array comes back empty. Fields: `meta.count`, `meta.current_page`.

Each match's `id` is the `contact_id` used by the get, update, and conversations endpoints.

## Authorization

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

## Query parameters

- `page` (integer, optional): 1-based page number of search results to retrieve. Omit to fetch the first page. Increment until the returned payload array is empty to iterate over all matches.
- `q` (string, optional): Search query text used to match contacts. Matches against contact fields such as name, email, and phone number.
- `sort` (string, optional): Attribute used to order the matched contacts. Accepted values: last_activity_at, name, email, phone_number. Prefix with a hyphen (e.g. -last_activity_at, -name, -email, -phone_number) for descending order.

## Response

### 200 Successful Response

Content type: `application/json`

```json
{
  "meta": {
    "count": 0,
    "current_page": "string"
  },
  "payload": [
    {
      "id": 0,
      "additional_attributes": {
        "city": "string",
        "country": "string",
        "description": "string",
        "company_name": "string",
        "country_code": "string",
        "social_profiles": {}
      },
      "availability_status": "string",
      "email": "string",
      "name": "string",
      "phone_number": "string",
      "blocked": false,
      "identifier": "string",
      "thumbnail": "string",
      "custom_attributes": {},
      "last_activity_at": 0,
      "created_at": 0
    }
  ]
}
```

### 422 Validation Error

Content type: `application/json`

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

## Request examples

### cURL

```bash
curl --request GET \
  --url 'https://api.nabrah.ai/api/ext/omni_v2/contact/search' \
  --header 'X-API-Key: <your-api-key>'
```

### Python

```python
import requests

url = "https://api.nabrah.ai/api/ext/omni_v2/contact/search"
headers = {"X-API-Key": "<your-api-key>"}

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

### JavaScript

```javascript
const response = await fetch("https://api.nabrah.ai/api/ext/omni_v2/contact/search", {
  method: "GET",
  headers: { "X-API-Key": "<your-api-key>" },
});

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

### Go

```go
package main

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

func main() {
	req, _ := http.NewRequest("GET", "https://api.nabrah.ai/api/ext/omni_v2/contact/search", nil)
	req.Header.Set("X-API-Key", "<your-api-key>")

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

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