//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Search contacts
* You can search for multiple contacts by the value of their attributes in order to fetch exactly who you want.
*/
export async function main(
auth: Intercom,
body: {
query:
| {
field?: string
operator?: '=' | '!=' | 'IN' | 'NIN' | '<' | '>' | '~' | '!~' | '^' | '$'
value?: string
}
| {
operator?: 'AND' | 'OR'
value?:
| {}[]
| {
field?: string
operator?: '=' | '!=' | 'IN' | 'NIN' | '<' | '>' | '~' | '!~' | '^' | '$'
value?: string
}[]
}
pagination?: { per_page?: number; starting_after?: string }
}
) {
const url = new URL(`https://api.intercom.io/contacts/search`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Intercom-Version': auth.apiVersion,
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 536 days ago