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

Created by armancejamstvena 290 days ago Viewed 53 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.70.1/mod.ts'
import { removeObjectEmptyFields } from 'https://deno.land/x/windmill_helpers@v1.0.0/mod.ts'

/**
 * Find more information about the parameters at
 * https://mailchimp.com/developer/marketing/api/campaigns/add-campaign/
 */
export async function main(
  auth: Resource<'mailchimp'>,
  type: 'regular' | 'plaintext' | 'rss' | 'variate',
  content_type: 'template' | 'multichannel' = 'template',
  rss_opts?: Record<string, any>,
  recipients?: Record<string, any>,
  variate_settings?: Record<string, any>,
  settings?: Record<string, any>,
  tracking?: Record<string, any>,
  social_card?: Record<string, any>,
) {
  const url = `https://${auth.server}.api.mailchimp.com/3.0/campaigns`;
  const body = {
    type,
    content_type,
    rss_opts,
    recipients,
    variate_settings,
    settings,
    tracking,
    social_card
  }

  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 115 days ago

Edited 23 days ago

No comments yet

Login to be able to comment