Edits history of script submission #219 for ' Add or Update Contact (sendgrid)'

  • deno
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    import sendgrid from "npm:@sendgrid/client@^7.7.0";
    
    /**
     * According to Sendgrid documentation, this is an asynchronous
     * process and the response will NOT contain immediate feedback,
     * only a `job_id` which then can be used to get the status
     * of the job.
     * The following script from WindmillHub performs this status check:
     * https://hub.windmill.dev/scripts/sendgrid/1449/get-contacts-import-status-sendgrid
     *
     * You can read more of the Sendgrid documentation at
     * https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact
     */
    type Sendgrid = {
      token: string;
    };
    export async function main(
      api_token: Sendgrid,
      contacts: {
        email: string;
        custom_fields: Record<string, string | number>;
      }[],
      list_ids?: string[],
    ) {
      sendgrid.setApiKey(api_token.token);
    
      try {
        contacts = contacts.map((c) => {
          return typeof c === "string" ? JSON.parse(c) : c;
        });
      } catch (error) {
        throw Error(`Tried to parse "contacts" argument because 
        it was an array of strings but failed with error:\n${error}`);
      }
    
      const body = removeObjectEmptyFields({
        contacts,
        list_ids,
      });
      const request = {
        url: `/v3/marketing/contacts`,
        method: "PUT",
        body,
      };
    
      try {
        const [_, body] = await sendgrid.request(request);
        return body;
      } catch (error) {
        throw Error("\n" + JSON.stringify(error?.response?.body || error));
      }
    }
    

    Submitted by hugo697 395 days ago

  • deno
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
    import sendgrid from "npm:@sendgrid/client@^7.7.0";
    
    /**
     * According to Sendgrid documentation, this is an asynchronous
     * process and the response will NOT contain immediate feedback,
     * only a `job_id` which then can be used to get the status
     * of the job.
     * The following script from WindmillHub performs this status check:
     * https://hub.windmill.dev/scripts/sendgrid/1449/get-contacts-import-status-sendgrid
     *
     * You can read more of the Sendgrid documentation at
     * https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact
     */
    type Sendgrid = {
      token: string;
    };
    export async function main(
      api_token: Sendgrid,
      contacts: {
        email: string;
        custom_fields: Record<string, string | number>;
      }[],
      list_ids?: string[],
    ) {
      sendgrid.setApiKey(api_token.token);
    
      try {
        contacts = contacts.map((c) => {
          return typeof c === "string" ? JSON.parse(c) : c;
        });
      } catch (error) {
        throw Error(`Tried to parse "contacts" argument because 
        it was an array of strings but failed with error:\n${error}`);
      }
    
      const body = removeObjectEmptyFields({
        contacts,
        list_ids,
      });
      const request = {
        url: `/v3/marketing/contacts`,
        method: "PUT",
        body,
      };
    
      try {
        const [_, body] = await sendgrid.request(request);
        return body;
      } catch (error) {
        throw Error("\n" + JSON.stringify(error?.response?.body || error));
      }
    }
    

    Submitted by admin 1028 days ago

  • deno
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts"
    import sendgrid from "npm:@sendgrid/client@^7.7.0"
    
    /**
     * According to Sendgrid documentation, this is an asynchronous 
     * process and the response will NOT contain immediate feedback, 
     * only a `job_id` which then can be used to get the status 
     * of the job.
     * The following script from WindmillHub performs this status check: 
     * https://hub.windmill.dev/scripts/sendgrid/1449/get-contacts-import-status-sendgrid
     * 
     * You can read more of the Sendgrid documentation at
     * https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact
     */
    type Sendgrid = {
      token: string;
    };
    export async function main(
      api_token: Sendgrid,
      contacts: {
        email: string,
        custom_fields: Record<string, string | number>
      }[],
      list_ids?: string[],
    ) {
      sendgrid.setApiKey(api_token.token)
    
      try {
        contacts = contacts.map(c => {
          return typeof c === 'string' ? JSON.parse(c) : c
        })
      } catch(error) {
        throw Error(`Tried to parse "contacts" argument because 
        it was an array of strings but failed with error:\n${error}`)
      }
    
      const body = removeObjectEmptyFields({
        contacts,
        list_ids
      })
      const request = {
        url: `/v3/marketing/contacts`,
        method: 'PUT',
        body
      }
    
      try {
        const [_, body] = await sendgrid.request(request)
        return body
      } catch (error) {
        throw Error('\n' + (JSON.stringify(error?.response?.body || error)))
      }
    }
    

    Submitted by admin 1031 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts"
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts"
    import sendgrid from "npm:@sendgrid/client@^7.7.0"
    
    /**
     * According to Sendgrid documentation, this is an asynchronous 
     * process and the response will NOT contain immediate feedback, 
     * only a `job_id` which then can be used to get the status 
     * of the job.
     * The following script from WindmillHub performs this status check: 
     * https://hub.windmill.dev/scripts/sendgrid/1449/get-contacts-import-status-sendgrid
     * 
     * You can read more of the Sendgrid documentation at
     * https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact
     */
    export async function main(
      api_token: wmill.Resource<"sendgrid">,
      contacts: {
        email: string,
        custom_fields: Record<string, string | number>
      }[],
      list_ids?: string[],
    ) {
      sendgrid.setApiKey(api_token.token)
    
      try {
        contacts = contacts.map(c => {
          return typeof c === 'string' ? JSON.parse(c) : c
        })
      } catch(error) {
        throw Error(`Tried to parse "contacts" argument because 
        it was an array of strings but failed with error:\n${error}`)
      }
    
      const body = removeObjectEmptyFields({
        contacts,
        list_ids
      })
      const request = {
        url: `/v3/marketing/contacts`,
        method: 'PUT',
        body
      }
    
      try {
        const [_, body] = await sendgrid.request(request)
        return body
      } catch (error) {
        throw Error('\n' + (JSON.stringify(error?.response?.body || error)))
      }
    }
    

    Submitted by adam186 1159 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts"
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts"
    import sendgrid from "npm:@sendgrid/client@^7.7.0"
    
    /**
     * According to Sendgrid documentation, this is an asynchronous 
     * process and the response will NOT contain immediate feedback, 
     * only a `job_id` which then can be used to get the status 
     * of the job.
     * The following script from WindmillHub performs this status check: 
     * https://hub.windmill.dev/scripts/sendgrid/1449/get-contacts-import-status-sendgrid
     * 
     * You can read more of the Sendgrid documentation at
     * https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact
     */
    export async function main(
      api_token: wmill.Resource<"sendgrid">,
      contacts: {
        email: string,
        custom_fields: Record<string, string | number>
      }[],
      list_ids?: string[],
    ) {
      sendgrid.setApiKey(api_token.token)
    
      try {
        contacts = contacts.map(c => {
          return typeof c === 'string' ? JSON.parse(c) : c
        })
      } catch(error) {
        throw Error(`Tried to parse "contacts" argument because 
        it was an array of strings but failed with error:\n${error}`)
      }
    
      const body = removeObjectEmptyFields({
        contacts,
        list_ids
      })
      const request = {
        url: `/v3/marketing/contacts`,
        method: 'PUT',
        body
      }
    
      try {
        const [_, body] = await sendgrid.request(request)
        return body
      } catch (error) {
        throw Error('\n' + (JSON.stringify(error?.response?.body || error)))
      }
    }
    

    Submitted by adam186 1194 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts"
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts"
    import sendgrid from "npm:@sendgrid/client@^7.7.0"
    
    /**
     * According to Sendgrid documentation, this is an asynchronous 
     * process and the response will NOT contain immediate feedback, 
     * only a `job_id` which then can be used to get the status 
     * of the job.
     * The following script from WindmillHub performs this status check: 
     * https://hub.windmill.dev/scripts/sendgrid/1449/get-contacts-import-status-sendgrid
     * 
     * You can read more of the Sendgrid documentation at
     * https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact
     */
    export async function main(
      api_token: wmill.Resource<"sendgrid">,
      contacts: {
        email: string,
        custom_fields: Record<string, string | number>
      }[],
      list_ids?: string[],
    ) {
      sendgrid.setApiKey(api_token.token)
    
      try {
        contacts = contacts.map(c => {
          return typeof c === 'string' ? JSON.parse(c) : c
        })
      } catch(error) {
        throw Error(`Tried to parse "contacts" argument because 
        it was an array of strings but failed with error:\n${error}`)
      }
    
      const body = removeObjectEmptyFields({
        contacts,
        list_ids
      })
      const request = {
        url: `/v3/marketing/contacts`,
        method: 'PUT',
        body
      }
    
      try {
        const [_, body] = await sendgrid.request(request)
        return body
      } catch (error) {
        throw Error('\n' + (JSON.stringify(error?.response?.body || error)))
      }
    }
    

    Submitted by adam186 1282 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts"
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts"
    import sendgrid from "npm:@sendgrid/client@^7.7.0"
    
    /**
     * According to Sendgrid documentation, this is an asynchronous 
     * process and the response will NOT contain immediate feedback, 
     * only a `job_id` which then can be used to get the status 
     * of the job.
     * 
     * You can read more about it at
     * https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact
     */
    export async function main(
      api_token: wmill.Resource<"sendgrid">,
      contacts: {
        email: string,
        custom_fields: Record<string, string | number>
      }[],
      list_ids?: string[],
    ) {
      sendgrid.setApiKey(api_token.token)
    
      try {
        contacts = contacts.map(c => {
          return typeof c === 'string' ? JSON.parse(c) : c
        })
      } catch(error) {
        throw Error(`Tried to parse "contacts" argument because 
        it was an array of strings but failed with error:\n${error}`)
      }
    
      const body = removeObjectEmptyFields({
        contacts,
        list_ids
      })
      const request = {
        url: `/v3/marketing/contacts`,
        method: 'PUT',
        body
      }
    
      try {
        const [_, body] = await sendgrid.request(request)
        return body
      } catch (error) {
        throw Error('\n' + (JSON.stringify(error?.response?.body || error)))
      }
    }
    

    Submitted by adam186 1282 days ago

  • deno
    import * as wmill from "https://deno.land/x/[email protected]/mod.ts"
    import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts"
    import sendgrid from "npm:@sendgrid/client@^7.7.0"
    
    export async function main(
      api_token: wmill.Resource<"sendgrid">,
      contacts: {
        email: string,
        custom_fields: Record<string, string | number>
      }[],
      list_ids?: string[],
    ) {
      sendgrid.setApiKey(api_token.token)
    
      try {
        contacts = contacts.map(c => {
          return typeof c === 'string' ? JSON.parse(c) : c
        })
      } catch(error) {
        throw Error(`Tried to parse "contacts" argument because 
        it was an array of strings but failed with error:\n${error}`)
      }
    
      const body = removeObjectEmptyFields({
        contacts,
        list_ids
      })
      const request = {
        url: `/v3/marketing/contacts`,
        method: 'PUT',
        body
      }
    
      try {
        const [_, body] = await sendgrid.request(request)
        return body
      } catch (error) {
        throw Error('\n' + (JSON.stringify(error?.response?.body || error)))
      }
    }
    

    Submitted by adam186 1282 days ago