type Campayn = {
apiKey: string
}
export async function main(
resource: Campayn,
listId: string,
body: {
id?: string
email?: string
}
) {
const endpoint = `https://campayn.com/api/v1/lists/${listId}/unsubscribe.json`
if (!body.id && !body.email) {
throw new Error('Please provide either an id or an email inside the body!')
}
const response = await fetch(endpoint, {
method: 'POST',
headers: {
Authorization: `TRUEREST apikey=${resource.apiKey}`
},
body: JSON.stringify(body)
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data
}
Submitted by hugo697 100 days ago