Edits history of script submission #10101 for ' Allows you to retrieve a specific attachment from a specific manual journal using a unique attachment Id (xero)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xero = {
      token: string;
    };
    /**
     * Allows you to retrieve a specific attachment from a specific manual journal using a unique attachment Id
     *
     */
    export async function main(
      auth: Xero,
      ManualJournalID: string,
      AttachmentID: string,
      xero_tenant_id: string,
      contentType: string,
    ) {
      const url = new URL(
        `https://api.xero.com/api.xro/2.0/ManualJournals/${ManualJournalID}/Attachments/${AttachmentID}`,
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Accept: 'application/json',
          "xero-tenant-id": xero_tenant_id,
          contentType: contentType,
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 515 days ago