Created by rubenmestwet 293 days ago Viewed 53 times 0 Points
No comments yet
import { Resource } from 'https://deno.land/x/windmill@v1.70.1/mod.ts'
/**
* @param fields *(optional)* A list of fields to return in the response.
* Reference parameters of sub-objects with dot notation.
*
* @param exclude_fields *(optional)* A list of fields to exclude from the response.
* Reference parameters of sub-objects with dot notation. If both `fields` and `exclude_fields`
* are present, then only `exclude_fields` will be used.
*/
export async function main(
auth: Resource<'mailchimp'>,
campaign_id: string,
fields?: string[],
exclude_fields?: string[]
) {
let url = `https://${auth.server}.api.mailchimp.com/3.0/campaigns/${campaign_id}?`
if(fields?.length) {
url += `fields=${fields.join(',')}`
}
if(exclude_fields?.length) {
url += `${fields?.length ? '&' : ''}exclude_fields=${exclude_fields.join(',')}`
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Bearer ${auth.api_key}`
}
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
No comments yet