import { removeObjectEmptyFields } from "https://deno.land/x/windmill_helpers@v1.0.0/mod.ts";
/**
* @param members_to_add *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*
* @param members_to_remove *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*/
type Mailchimp = {
api_key: string;
server: string;
};
export async function main(
auth: Mailchimp,
list_id: string,
segment_id: string,
members_to_add?: string[],
members_to_remove?: string[],
) {
const url = new URL(
`https://${auth.server}.api.mailchimp.com/3.0/lists/${list_id}/segments/${segment_id}`,
);
const body = {
members_to_add,
members_to_remove,
};
removeObjectEmptyFields(body, true, false);
if (!Object.keys(body).length) {
return "No members were declared to be added or removed.";
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.api_key}`,
},
body: JSON.stringify(body),
});
if (!response.ok) {
throw Error(await response.text());
}
return await response.json();
}
Submitted by admin 250 days ago
import { removeObjectEmptyFields } from 'https://deno.land/x/windmill_helpers@v1.0.0/mod.ts'
/**
* @param members_to_add *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*
* @param members_to_remove *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*/
type Mailchimp = {
api_key: string;
server: string;
};
export async function main(
auth: Mailchimp,
list_id: string,
segment_id: string,
members_to_add?: string[],
members_to_remove?: string[]
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists/${list_id}/segments/${segment_id}`)
const body = {
members_to_add,
members_to_remove
}
removeObjectEmptyFields(body, true, false)
if(!Object.keys(body).length) {
return 'No members were declared to be added or removed.'
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${auth.api_key}`
},
body: JSON.stringify(body)
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
Submitted by admin 254 days ago
import { Resource } from 'https://deno.land/x/windmill@v1.85.0/mod.ts'
import { removeObjectEmptyFields } from 'https://deno.land/x/windmill_helpers@v1.0.0/mod.ts'
/**
* @param members_to_add *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*
* @param members_to_remove *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*/
export async function main(
auth: Resource<'mailchimp'>,
list_id: string,
segment_id: string,
members_to_add?: string[],
members_to_remove?: string[]
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists/${list_id}/segments/${segment_id}`)
const body = {
members_to_add,
members_to_remove
}
removeObjectEmptyFields(body, true, false)
if(!Object.keys(body).length) {
return 'No members were declared to be added or removed.'
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${auth.api_key}`
},
body: JSON.stringify(body)
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
Submitted by adam186 382 days ago
import { Resource } from 'https://deno.land/x/windmill@v1.70.1/mod.ts'
import { removeObjectEmptyFields } from 'https://deno.land/x/windmill_helpers@v1.0.0/mod.ts'
/**
* @param members_to_add *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*
* @param members_to_remove *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*/
export async function main(
auth: Resource<'mailchimp'>,
list_id: string,
segment_id: string,
members_to_add?: string[],
members_to_remove?: string[]
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists/${list_id}/segments/${segment_id}`)
const body = {
members_to_add,
members_to_remove
}
removeObjectEmptyFields(body, true, false)
if(!Object.keys(body).length) {
return 'No members were declared to be added or removed.'
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${auth.api_key}`
},
body: JSON.stringify(body)
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
Submitted by adam186 417 days ago
import { Resource } from 'https://deno.land/x/windmill@v1.55.0/mod.ts'
import { removeObjectEmptyFields } from 'https://deno.land/x/windmill_helpers@v1.0.0/mod.ts'
/**
* @param members_to_add *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*
* @param members_to_remove *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*/
export async function main(
auth: Resource<'mailchimp'>,
list_id: string,
segment_id: string,
members_to_add?: string[],
members_to_remove?: string[]
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists/${list_id}/segments/${segment_id}`)
const body = {
members_to_add,
members_to_remove
}
removeObjectEmptyFields(body, true, false)
if(!Object.keys(body).length) {
return 'No members were declared to be added or removed.'
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${auth.api_key}`
},
body: JSON.stringify(body)
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
Submitted by adam186 488 days ago
/**
* @param server The data center for your Mailchimp account.
*
* @param members_to_add *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*
* @param members_to_remove *(optional)* An array of emails to be used for a static segment.
* Any emails provided that are not present on the list will be ignored.
* A maximum of 500 members can be sent.
*/
export async function main(
api_key: string,
server: string,
list_id: string,
segment_id: string,
members_to_add?: string[],
members_to_remove?: string[]
) {
const url = new URL(`https://${server}.api.mailchimp.com/3.0/lists/${list_id}/segments/${segment_id}`)
const body = {
members_to_add,
members_to_remove
}
removeEmptyFields(body)
if(!Object.keys(body).length) {
return 'No members were declared to be added or removed.'
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${api_key}`
},
body: JSON.stringify(body)
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
function removeEmptyFields(obj: Record<string, any> | undefined) {
if(!obj || typeof obj !== 'object') {
return
}
for(const key in obj) {
const value = obj[<keyof typeof obj>key]
if(
value === undefined ||
value === null ||
value === '' ||
(typeof value === 'object' && !Object.keys(value).length)
) {
delete obj[<keyof typeof obj>key]
}
}
}
Submitted by adam186 507 days ago