Created by adam186 118 days ago Viewed 58 times 0 Points
Get information about segments of a specific list.
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.
*
* @param since_created_at *(optional)* Uses ISO 8601 time format: `2022-10-21T15:41:36+00:00`.
* @param before_created_at *(optional)* Uses ISO 8601 time format: `2022-10-21T15:41:36+00:00`.
* @param since_updated_at *(optional)* Uses ISO 8601 time format: `2022-10-21T15:41:36+00:00`.
* @param before_updated_at *(optional)* Uses ISO 8601 time format: `2022-10-21T15:41:36+00:00`.
*/
export async function main(
auth: Resource<'mailchimp'>,
list_id: string,
fields?: string[],
exclude_fields?: string[],
count?: number,
offset?: number,
type?: string,
since_created_at?: string,
before_created_at?: string,
since_updated_at?: string,
before_updated_at?: string,
include_cleaned?: boolean,
include_transactional?: boolean,
include_unsubscribed?: boolean,
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists/${list_id}/segments`)
const params = {
fields,
exclude_fields,
count,
offset,
type,
since_created_at,
before_created_at,
since_updated_at,
before_updated_at,
include_cleaned,
include_transactional,
include_unsubscribed
}
for(const key in params) {
const value = params[<keyof typeof params>key]
if(value) {
url.searchParams.append(key, Array.isArray(value) ? value.join(',') : '' + value)
}
}
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