Edits history of script submission #16416 for ' Update Document (holded)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Holded = {
      apiKey: string;
    };
    /**
     * Update Document
     * Update a specific document. {lotSku} field is only needed when {kind} is lots.
     */
    export async function main(
      auth: Holded,
      docType: string,
      documentId: string,
      body: {
        desc?: string;
        notes?: string;
        language?: string;
        date?: number;
        paymentMethod?: string;
        warehouseId?: string;
        items?: {
          name?: string;
          desc?: string;
          subtotal?: number;
          tax?: number;
          tags?: string[];
          units?: number;
          discount?: number;
          accountingAccountId?: string;
          kind?: string;
          sku?: string;
          lotSku?: string;
          supplied?: string;
        }[];
        salesChannelId?: string;
        expAccountId?: string;
        customFields?: { field?: string; value?: string }[];
      },
    ) {
      const url = new URL(
        `https://api.holded.com/api/invoicing/v1/documents/${docType}/${documentId}`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          key: auth.apiKey,
        },
        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