Edits history of script submission #4019 for ' Create Organization (zendesk)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Zendesk = {
      username: string;
      password: string;
      subdomain: string;
    };
    /**
     * Create Organization
     * You must provide a unique `name` for each organization. Normally
    the system doesn't allow records to be created with identical names.
    However, a race condition can occur if you make two or more identical
    POSTs very close to each other, causing the records to have identical
    organization names.
    
    #### Allowed For
    
    * Admins
    * Agents assigned to a custom role with permissions to manage organizations (Enterprise only)
    
     */
    export async function main(auth: Zendesk) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/organizations`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      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;
    };
    /**
     * Create Organization
     * You must provide a unique `name` for each organization. Normally
    the system doesn't allow records to be created with identical names.
    However, a race condition can occur if you make two or more identical
    POSTs very close to each other, causing the records to have identical
    organization names.
    
    #### Allowed For
    
    * Admins
    * Agents assigned to a custom role with permissions to manage organizations (Enterprise only)
    
     */
    export async function main(auth: Zendesk) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/organizations`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 923 days ago