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/
 */
type Mailchimp = {
  api_key: string;
  server: string;
};
export async function main(
  auth: 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 hugo697 177 days ago
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/
 */
type Mailchimp = {
  api_key: string;
  server: string;
};
export async function main(
  auth: 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 admin 810 days ago
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/
 */
type Mailchimp = {
  api_key: string;
  server: string;
};
export async function main(
  auth: 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 admin 813 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'
/**
 * 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 941 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'
/**
 * 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 976 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'
/**
 * 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 1047 days ago
/**
 * @param server The data center for your Mailchimp account.
 *
 * Find more information about the parameters at
 * https://mailchimp.com/developer/marketing/api/campaigns/add-campaign/
 */
export async function main(
  api_key: string,
  server: string,
  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://${server}.api.mailchimp.com/3.0/campaigns`;
  const body = {
    type,
    content_type,
    rss_opts,
    recipients,
    variate_settings,
    settings,
    tracking,
    social_card
  }
  for(const key in body) {
    const field = body[<keyof typeof body>key]
    if(!field || !Object.keys(field).length) {
      delete body[<keyof typeof body>key]
    }
  }
  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();
}
Submitted by adam186 1068 days ago
/**
 * @param server The data center for your Mailchimp account.
 *
 * Find more information about the parameters at
 * https://mailchimp.com/developer/marketing/api/campaigns/add-campaign/
 */
export async function main(
  api_key: string,
  server: string,
  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://${server}.api.mailchimp.com/3.0/campaigns`;
  const body = {
    type,
    content_type,
    rss_opts,
    recipients,
    variate_settings,
    settings,
    tracking,
    social_card
  }
  for(const key in body) {
    const field = body[<keyof typeof body>key]
    if(!field || !Object.keys(field).length) {
      delete body[<keyof typeof body>key]
    }
  }
  const response = await fetch(url, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${api_key}`,
    },
    body: JSON.stringify(body),
  });
  return await response.json();
}
Submitted by adam186 1068 days ago