Edits history of script submission #201 for ' Create Campaign (mailchimp)'

  • deno
    One script reply has been approved by the moderators
    Ap­pro­ved
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/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 378 days ago

  • deno
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/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 1010 days ago

  • deno
    import { removeObjectEmptyFields } from 'https://deno.land/x/[email protected]/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 1013 days ago

  • deno
    import { Resource } from 'https://deno.land/x/[email protected]/mod.ts'
    import { removeObjectEmptyFields } from 'https://deno.land/x/[email protected]/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 1142 days ago

  • deno
    import { Resource } from 'https://deno.land/x/[email protected]/mod.ts'
    import { removeObjectEmptyFields } from 'https://deno.land/x/[email protected]/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 1177 days ago

  • deno
    import { Resource } from 'https://deno.land/x/[email protected]/mod.ts'
    import { removeObjectEmptyFields } from 'https://deno.land/x/[email protected]/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 1247 days ago

  • deno
    /**
     * @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 1268 days ago

  • deno
    /**
     * @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 1268 days ago