Edits history of script submission #14335 for ' Create Box Skill cards on file (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Create Box Skill cards on file
     * Applies one or more Box Skills metadata cards to a file.
     */
    export async function main(
      auth: Box,
      file_id: string,
      body: {
        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 };
            }[];
      },
    ) {
      const url = new URL(
        `https://api.box.com/2.0/files/${file_id}/metadata/global/boxSkillsCards`,
      );
    
      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