import { removeObjectEmptyFields } from "https://deno.land/x/windmill_helpers@v1.0.1/mod.ts";
/**
* Find more information about the parameters at
* https://mailchimp.com/developer/marketing/api/lists/add-list/
*/
type Mailchimp = {
api_key: string;
server: string;
};
export async function main(
auth: Mailchimp,
name: string,
permission_reminder: string,
campaign_from_name: string,
campaign_from_email: string,
campaign_subject: string,
campaign_language: string,
email_type_option: boolean,
contact_company: string,
contact_country: string,
contact_city: string,
contact_address1: string,
contact_address2?: string,
contact_state?: string,
contact_zip?: string,
contact_phone?: string,
notify_on_subscribe?: string,
notify_on_unsubscribe?: string,
use_archive_bar?: boolean,
double_optin?: boolean,
marketing_permissions?: boolean,
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists`);
const body = {
name,
contact: {
company: contact_company,
country: contact_country,
city: contact_city,
address1: contact_address1,
address2: contact_address2,
state: contact_state,
zip: contact_zip,
phone: contact_phone,
},
permission_reminder,
campaign_defaults: {
from_name: campaign_from_name,
from_email: campaign_from_email,
subject: campaign_subject,
language: campaign_language,
},
email_type_option,
use_archive_bar,
notify_on_subscribe,
notify_on_unsubscribe,
double_optin,
marketing_permissions,
};
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.api_key}`,
},
body: JSON.stringify(removeObjectEmptyFields(body)),
});
if (!response.ok) {
throw Error(await response.text());
}
return await response.json();
}
Submitted by admin 502 days ago
import { removeObjectEmptyFields } from 'https://deno.land/x/windmill_helpers@v1.0.1/mod.ts'
/**
* Find more information about the parameters at
* https://mailchimp.com/developer/marketing/api/lists/add-list/
*/
type Mailchimp = {
api_key: string;
server: string;
};
export async function main(
auth: Mailchimp,
name: string,
permission_reminder: string,
campaign_from_name: string,
campaign_from_email: string,
campaign_subject: string,
campaign_language: string,
email_type_option: boolean,
contact_company: string,
contact_country: string,
contact_city: string,
contact_address1: string,
contact_address2?: string,
contact_state?: string,
contact_zip?: string,
contact_phone?: string,
notify_on_subscribe?: string,
notify_on_unsubscribe?: string,
use_archive_bar?: boolean,
double_optin?: boolean,
marketing_permissions?: boolean
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists`)
const body = {
name,
contact: {
company: contact_company,
country: contact_country,
city: contact_city,
address1: contact_address1,
address2: contact_address2,
state: contact_state,
zip: contact_zip,
phone: contact_phone
},
permission_reminder,
campaign_defaults: {
from_name: campaign_from_name,
from_email: campaign_from_email,
subject: campaign_subject,
language: campaign_language,
},
email_type_option,
use_archive_bar,
notify_on_subscribe,
notify_on_unsubscribe,
double_optin,
marketing_permissions
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${auth.api_key}`
},
body: JSON.stringify(removeObjectEmptyFields(body))
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
Submitted by admin 505 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.1/mod.ts'
/**
* Find more information about the parameters at
* https://mailchimp.com/developer/marketing/api/lists/add-list/
*/
export async function main(
auth: Resource<'mailchimp'>,
name: string,
permission_reminder: string,
campaign_from_name: string,
campaign_from_email: string,
campaign_subject: string,
campaign_language: string,
email_type_option: boolean,
contact_company: string,
contact_country: string,
contact_city: string,
contact_address1: string,
contact_address2?: string,
contact_state?: string,
contact_zip?: string,
contact_phone?: string,
notify_on_subscribe?: string,
notify_on_unsubscribe?: string,
use_archive_bar?: boolean,
double_optin?: boolean,
marketing_permissions?: boolean
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists`)
const body = {
name,
contact: {
company: contact_company,
country: contact_country,
city: contact_city,
address1: contact_address1,
address2: contact_address2,
state: contact_state,
zip: contact_zip,
phone: contact_phone
},
permission_reminder,
campaign_defaults: {
from_name: campaign_from_name,
from_email: campaign_from_email,
subject: campaign_subject,
language: campaign_language,
},
email_type_option,
use_archive_bar,
notify_on_subscribe,
notify_on_unsubscribe,
double_optin,
marketing_permissions
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${auth.api_key}`
},
body: JSON.stringify(removeObjectEmptyFields(body))
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
Submitted by adam186 634 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.1/mod.ts'
/**
* Find more information about the parameters at
* https://mailchimp.com/developer/marketing/api/lists/add-list/
*/
export async function main(
auth: Resource<'mailchimp'>,
name: string,
permission_reminder: string,
campaign_from_name: string,
campaign_from_email: string,
campaign_subject: string,
campaign_language: string,
email_type_option: boolean,
contact_company: string,
contact_country: string,
contact_city: string,
contact_address1: string,
contact_address2?: string,
contact_state?: string,
contact_zip?: string,
contact_phone?: string,
notify_on_subscribe?: string,
notify_on_unsubscribe?: string,
use_archive_bar?: boolean,
double_optin?: boolean,
marketing_permissions?: boolean
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists`)
const body = {
name,
contact: {
company: contact_company,
country: contact_country,
city: contact_city,
address1: contact_address1,
address2: contact_address2,
state: contact_state,
zip: contact_zip,
phone: contact_phone
},
permission_reminder,
campaign_defaults: {
from_name: campaign_from_name,
from_email: campaign_from_email,
subject: campaign_subject,
language: campaign_language,
},
email_type_option,
use_archive_bar,
notify_on_subscribe,
notify_on_unsubscribe,
double_optin,
marketing_permissions
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${auth.api_key}`
},
body: JSON.stringify(removeObjectEmptyFields(body))
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
Submitted by adam186 669 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.1/mod.ts'
/**
* Find more information about the parameters at
* https://mailchimp.com/developer/marketing/api/lists/add-list/
*/
export async function main(
auth: Resource<'mailchimp'>,
name: string,
permission_reminder: string,
campaign_from_name: string,
campaign_from_email: string,
campaign_subject: string,
campaign_language: string,
email_type_option: boolean,
contact_company: string,
contact_country: string,
contact_city: string,
contact_address1: string,
contact_address2?: string,
contact_state?: string,
contact_zip?: string,
contact_phone?: string,
notify_on_subscribe?: string,
notify_on_unsubscribe?: string,
use_archive_bar?: boolean,
double_optin?: boolean,
marketing_permissions?: boolean
) {
const url = new URL(`https://${auth.server}.api.mailchimp.com/3.0/lists`)
const body = {
name,
contact: {
company: contact_company,
country: contact_country,
city: contact_city,
address1: contact_address1,
address2: contact_address2,
state: contact_state,
zip: contact_zip,
phone: contact_phone
},
permission_reminder,
campaign_defaults: {
from_name: campaign_from_name,
from_email: campaign_from_email,
subject: campaign_subject,
language: campaign_language,
},
email_type_option,
use_archive_bar,
notify_on_subscribe,
notify_on_unsubscribe,
double_optin,
marketing_permissions
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${auth.api_key}`
},
body: JSON.stringify(removeObjectEmptyFields(body))
})
if(!response.ok) {
throw Error(await response.text())
}
return await response.json()
}
Submitted by adam186 740 days ago
/**
* @param server The data center for your Mailchimp account.
*
* Find more information about the parameters at
* https://mailchimp.com/developer/marketing/api/lists/add-list/
*/
export async function main(
api_key: string,
server: string,
name: string,
permission_reminder: string,
campaign_from_name: string,
campaign_from_email: string,
campaign_subject: string,
campaign_language: string,
email_type_option: boolean,
contact_company: string,
contact_country: string,
contact_city: string,
contact_address1: string,
contact_address2?: string,
contact_state?: string,
contact_zip?: string,
contact_phone?: string,
notify_on_subscribe?: string,
notify_on_unsubscribe?: string,
use_archive_bar?: boolean,
double_optin?: boolean,
marketing_permissions?: boolean
) {
const url = new URL(`https://${server}.api.mailchimp.com/3.0/lists`)
const campaign_defaults = {
from_name: campaign_from_name,
from_email: campaign_from_email,
subject: campaign_subject,
language: campaign_language,
}
removeEmptyFields(campaign_defaults)
const contact = {
company: contact_company,
country: contact_country,
city: contact_city,
address1: contact_address1,
address2: contact_address2,
state: contact_state,
zip: contact_zip,
phone: contact_phone
}
removeEmptyFields(contact)
const body = {
name,
contact,
permission_reminder,
campaign_defaults,
email_type_option,
use_archive_bar,
notify_on_subscribe,
notify_on_unsubscribe,
double_optin,
marketing_permissions
}
removeEmptyFields(body)
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>) {
for(const key in obj) {
const value = obj[<keyof typeof obj>key]
if(
value === undefined ||
value === null ||
value === '' ||
(typeof value === 'object' && !Object.keys(obj).length)
) {
delete obj[<keyof typeof obj>key]
}
}
}
Submitted by adam186 760 days ago