//native
type Actimo = {
apiKey: string
}
export async function main(
auth: Actimo,
targetId: string,
sourceId: string | undefined,
sourceAuthCode: string | undefined,
body: { allow_email?: false | true; allow_sms?: false | true } & {
allow_contact_info?: false | true
}
) {
const url = new URL(`https://actimo.com/api/v1/contacts/${targetId}/updateSettings`)
for (const [k, v] of [
['sourceId', sourceId],
['sourceAuthCode', sourceAuthCode]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
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 16 days ago