//native
type Intercom = {
apiVersion: string
token: string
}
/**
* Update a visitor
* Sending a PUT request to `/visitors` will result in an update of an existing Visitor.
**Option 1.** You can update a visitor by passing in the `user_id` of the visitor in the Request body.
**Option 2.** You can update a visitor by passing in the `id` of the visitor in the Request body.
*/
export async function main(
auth: Intercom,
body: {} & {
id?: string
user_id?: string
name?: string
custom_attributes?: {}
}
) {
const url = new URL(`https://api.intercom.io/visitors`)
const response = await fetch(url, {
method: 'PUT',
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