Edits history of script submission #14316 for ' Add initial classifications (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Add initial classifications
     * When an enterprise does not yet have any classifications, this API call
    initializes the classification template with an initial set of
    classifications.
    
    If an enterprise already has a classification, the template will already
    exist and instead an API call should be made to add additional
    classifications.
     */
    export async function main(
      auth: Box,
      body: {
        scope: "enterprise";
        templateKey: "securityClassification-6VMVochwUWo";
        displayName: "Classification";
        hidden?: false | true;
        copyInstanceOnItemCopy?: false | true;
        fields: {
          type: "enum";
          key: "Box__Security__Classification__Key";
          displayName: "Classification";
          hidden?: false | true;
          options: {
            key: string;
            staticConfig?: {
              classification?: {
                classificationDefinition?: string;
                colorID?: number;
              };
            };
          }[];
        }[];
      },
    ) {
      const url = new URL(
        `https://api.box.com/2.0/metadata_templates/schema#classifications`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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