//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Create or update a tag, Tag or untag companies, Tag contacts
* You can use this endpoint to perform the following operations:
**1.
*/
export async function main(
auth: Intercom,
body:
| { name: string; id?: string }
| { name: string; companies: { id?: string; company_id?: string }[] }
| {
name: string
companies: { id?: string; company_id?: string; untag?: false | true }[]
}
| { name: string; users: { id?: string }[] }
) {
const url = new URL(`https://api.intercom.io/tags`)
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