Edits history of script submission #14543 for ' Update all Box Skill cards on file (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Update all Box Skill cards on file
     * An alternative method that can be used to overwrite and update all Box Skill
    metadata cards on a file.
     */
    export async function main(
      auth: Box,
      skill_id: string,
      body: {
        status:
          | "invoked"
          | "processing"
          | "success"
          | "transient_failure"
          | "permanent_failure";
        metadata: {
          cards?:
            | {
                created_at?: string;
                type: "skill_card";
                skill_card_type: "keyword";
                skill_card_title?: { code?: string; message: string };
                skill: { type: "service"; id: string };
                invocation: { type: "skill_invocation"; id: string };
                entries: { text?: string }[];
              }
            | {
                created_at?: string;
                type: "skill_card";
                skill_card_type: "timeline";
                skill_card_title?: { code?: string; message: string };
                skill: { type: "service"; id: string };
                invocation: { type: "skill_invocation"; id: string };
                duration?: number;
                entries: {
                  text?: string;
                  appears?: { start?: number; end?: number }[];
                  image_url?: string;
                }[];
              }
            | {
                created_at?: string;
                type: "skill_card";
                skill_card_type: "transcript";
                skill_card_title?: { code?: string; message: string };
                skill: { type: "service"; id: string };
                invocation: { type: "skill_invocation"; id: string };
                duration?: number;
                entries: { text?: string; appears?: { start?: number }[] }[];
              }
            | {
                created_at?: string;
                type: "skill_card";
                skill_card_type: "status";
                skill_card_title?: { code?: string; message: string };
                status: {
                  code:
                    | "invoked"
                    | "processing"
                    | "success"
                    | "transient_failure"
                    | "permanent_failure";
                  message?: string;
                };
                skill: { type: "service"; id: string };
                invocation: { type: "skill_invocation"; id: string };
              }[];
        };
        file: { type?: "file"; id?: string };
        file_version?: { type?: "file_version"; id?: string };
        usage?: { unit?: string; value?: number };
      },
    ) {
      const url = new URL(`https://api.box.com/2.0/skill_invocations/${skill_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