Edits history of script submission #14557 for ' Update storage policy assignment (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Update storage policy assignment
     * Updates a specific storage policy assignment.
     */
    export async function main(
      auth: Box,
      storage_policy_assignment_id: string,
      body: { storage_policy: { type: "storage_policy"; id: string } },
    ) {
      const url = new URL(
        `https://api.box.com/2.0/storage_policy_assignments/${storage_policy_assignment_id}`,
      );
    
      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