Edits history of script submission #16310 for ' Create Document (holded)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Holded = {
      apiKey: string;
    };
    /**
     * Create Document
     * Create a new document type.
     */
    export async function main(
      auth: Holded,
      docType: string,
      body: {
        applyContactDefaults?: false | true;
        contactCode?: string;
        contactId?: string;
        contactName?: string;
        contactEmail?: string;
        contactAddress?: string;
        contactCity?: string;
        contactCp?: string;
        contactProvince?: string;
        contactCountryCode?: string;
        desc?: string;
        date: number;
        notes?: string;
        salesChannelId?: string;
        paymentMethodId?: string;
        designId?: string;
        language?: string;
        warehouseId?: string;
        approveDoc?: false | true;
        items?: {
          name?: string;
          desc?: string;
          units?: number;
          sku?: string;
          serviceId?: string;
          accountingAccountId?: string;
          subtotal?: number;
          discount?: number;
          tax?: number;
          taxes?: string[];
          supplied?: string;
          tags?: string[];
        }[];
        customFields?: { field?: string; value?: string }[];
        invoiceNum?: string;
        numSerieId?: string;
        currency?: string;
        currencyChange?: number;
        tags?: string[];
        dueDate?: number;
        shippingAddress?: string;
        shippingPostalCode?: string;
        shippingCity?: string;
        shippingProvince?: string;
        shippingCountry?: string;
        salesChannel?: number;
      },
    ) {
      const url = new URL(
        `https://api.holded.com/api/invoicing/v1/documents/${docType}`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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