Edits history of script submission #11491 for ' Get File By Id (ai21)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Ai21 = {
      apiKey: string;
    };
    /**
     * Get File By Id
     * Retrieve a list of documents in the user's library. Optionally specify a
    filter to find only files with matching labels or paths. This method
    returns only metadata about files; to download a file, call
    `GET .../files/{file_id}/download`
    
    When specifying qualifiers with your request, only files that match
    _all_ qualifiers will be returns. So, for example, if you specify
    `label='financial'` and `status='UPLOADED'`, only files with the label
    "financial" AND status UPLOADED will be returned.
     */
    export async function main(auth: Ai21, file_id: string) {
      const url = new URL(
        `https://api.ai21.com/studio/v1/library/files/${file_id}`,
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 427 days ago