type Acumbamail = {
authToken: string
}
export async function main(
resource: Acumbamail,
body: {
list_id: number
merge_fields: { [key: string]: string }
double_optin?: boolean
update_subscriber?: boolean
}
) {
const endpoint = 'https://acumbamail.com/api/1/addSubscriber/'
const formData = new FormData()
Object.entries(body.merge_fields).forEach(([key, value]) => {
formData.append(`merge_fields[${key}]`, value)
})
formData.append('auth_token', resource.authToken)
formData.append('list_id', body.list_id.toString())
formData.append('double_optin', body.double_optin ? '1' : '0')
formData.append('update_subscriber', body.update_subscriber ? '1' : '0')
formData.append('complete_json', '1')
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Cache-Control': 'no-cache'
},
body: formData
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data
}
Submitted by hugo697 41 days ago