Edits history of script submission #20553 for ' Update User (smartsheet)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Smartsheet = {
      token: string;
      baseUrl: string;
    };
    /**
     * Update User
     * Updates the user specified in the URL.
     */
    export async function main(
      auth: Smartsheet,
      userId: string,
      body: {
        admin?: false | true;
        licensedSheetCreator?: false | true;
        firstName?: string;
        lastName?: string;
        groupAdmin?: false | true;
        resourceViewer?: false | true;
      },
    ) {
      const url = new URL(`${auth.baseUrl}/users/${userId}`);
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        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 235 days ago