Edits history of script submission #14348 for ' Create metadata instance on folder (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Create metadata instance on folder
     * Applies an instance of a metadata template to a folder.
    
    In most cases only values that are present in the metadata template
    will be accepted, except for the `global.properties` template which accepts
    any key-value pair.
    
    To display the metadata template in the Box web app the enterprise needs to be
    configured to enable **Cascading Folder Level Metadata** for the user in the
    admin console.
     */
    export async function main(
      auth: Box,
      folder_id: string,
      scope: "global" | "enterprise",
      template_key: string,
      body: {},
    ) {
      const url = new URL(
        `https://api.box.com/2.0/folders/${folder_id}/metadata/${scope}/${template_key}`,
      );
    
      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