Edits history of script submission #4182 for ' Merge End Users (zendesk)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Zendesk = {
      username: string;
      password: string;
      subdomain: string;
    };
    /**
     * Merge End Users
     * Merges the end user specified in the path parameter into the existing end user specified in the request body.
    
    Any two end users can be merged with the exception of end users created by sharing agreements.
    
    Agents and admins cannot be merged.
    
    For more information about how user data is merged, see [Merging a user's duplicate account](https://support.zendesk.com/hc/en-us/articles/4408887695898) in Zendesk help.
    
    #### Allowed For
    
    * Admins or agents with permission to edit end users
    
     */
    export async function main(
      auth: Zendesk,
      user_id: string,
      body: {
        user?: {
          custom_role_id?: string;
          email?: string;
          external_id?: string;
          identities?: { type?: string; value?: string; [k: string]: unknown }[];
          name?: string;
          organization?: { name?: string; [k: string]: unknown };
          organization_id?: string;
          role?: string;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/users/${user_id}/merge`
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 377 days ago

  • nativets
    type Zendesk = {
      username: string;
      password: string;
      subdomain: string;
    };
    /**
     * Merge End Users
     * Merges the end user specified in the path parameter into the existing end user specified in the request body.
    
    Any two end users can be merged with the exception of end users created by sharing agreements.
    
    Agents and admins cannot be merged.
    
    For more information about how user data is merged, see [Merging a user's duplicate account](https://support.zendesk.com/hc/en-us/articles/4408887695898) in Zendesk help.
    
    #### Allowed For
    
    * Admins or agents with permission to edit end users
    
     */
    export async function main(
      auth: Zendesk,
      user_id: string,
      body: {
        user?: {
          custom_role_id?: string;
          email?: string;
          external_id?: string;
          identities?: { type?: string; value?: string; [k: string]: unknown }[];
          name?: string;
          organization?: { name?: string; [k: string]: unknown };
          organization_id?: string;
          role?: string;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/users/${user_id}/merge`
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 923 days ago