Count a filter
const url = 'https://api.threadkite.app/v1/segments/preview';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"filter":{"conditions":[{"type":"field","field":"threads.tagIds","op":"equals","value":["example"]}]}}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.threadkite.app/v1/segments/preview \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "filter": { "conditions": [ { "type": "field", "field": "threads.tagIds", "op": "equals", "value": [ "example" ] } ] } }'How many contacts a filter matches now and the first 50 by name, before saving it. Only contacts with a thread in an inbox you can see count.
Authorizations
Section titled “Authorizations”Request Bodyrequired
Section titled “Request Bodyrequired”object
object
Every condition must hold; an empty list is everyone
object
What to check: contact.<name|email|phone|createdAt|field key>, consent.<channel> or threads.<tagIds|sourceIds|locationIds|inboxIds|itemIds|states|scoreBand|lastActivityAt|lastContactMessageAt|leadCount|hasSale> (across their threads)
Example
threads.tagIdsobject
Example
order.paidExample
30False: it has not happened in that time
object
One of these must hold
object
What to check: contact.<name|email|phone|createdAt|field key>, consent.<channel> or threads.<tagIds|sourceIds|locationIds|inboxIds|itemIds|states|scoreBand|lastActivityAt|lastContactMessageAt|leadCount|hasSale> (across their threads)
Example
threads.tagIdsobject
Example
order.paidExample
30False: it has not happened in that time
Responses
Section titled “Responses”object
Contacts in the segment now (only contacts with a thread in an inbox you can see count)
The first 50, by name
object
E.164
Example generated
{ "count": 1, "contacts": [ { "id": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "name": "example", "email": "example", "phone": "example" } ]}object
Stable machine-readable reason
With code invalid: every problem with the request, by field (message is the first)
object
Dotted path inside the item, e.g. attributes.price.amountMinor
Example
{ "statusCode": 403, "code": "forbidden", "message": "You do not have permission to do that.", "errors": [ { "message": "Enter the make" } ]}Missing or invalid API key
object
Stable machine-readable reason
With code invalid: every problem with the request, by field (message is the first)
object
Dotted path inside the item, e.g. attributes.price.amountMinor
Example
{ "statusCode": 403, "code": "forbidden", "message": "You do not have permission to do that.", "errors": [ { "message": "Enter the make" } ]}The organisation is on the Free plan (code upgrade_required)
object
Stable machine-readable reason
The feature that needs Pro
Where to upgrade or pay, in the web app
Example
{ "statusCode": 402, "code": "upgrade_required", "message": "Connections are part of Pro. Upgrade to connect texts, calls and more.", "feature": "extraSeats", "upgradePath": "/settings/billing"}The key does not have the scope (or the person the permission)
object
Stable machine-readable reason
With code invalid: every problem with the request, by field (message is the first)
object
Dotted path inside the item, e.g. attributes.price.amountMinor
Example
{ "statusCode": 403, "code": "forbidden", "message": "You do not have permission to do that.", "errors": [ { "message": "Enter the make" } ]}object
Stable machine-readable reason
With code invalid: every problem with the request, by field (message is the first)
object
Dotted path inside the item, e.g. attributes.price.amountMinor
Example
{ "statusCode": 403, "code": "forbidden", "message": "You do not have permission to do that.", "errors": [ { "message": "Enter the make" } ]}Rate limit reached
object
Stable machine-readable reason
Seconds until another request will be accepted
Example
{ "statusCode": 429, "code": "rate_limited", "message": "Too many requests. Each key can make 120 requests a minute; try again in 12 seconds.", "retryAfter": 12}