Create List ( mailchimp)
One script reply has been approved by the moderators Verified

Created by armancedinari 360 days ago Viewed 69 times 0 Points

No comments yet

Login to be able to comment
Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
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 185 days ago

Edited 59 days ago

No comments yet

Login to be able to comment