Edits history of script submission #21978 for ' Update a Purchase Order (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update a Purchase Order
     * Updates a new Purchase Order in Zoho Inventory. Description about extra parameter ignore_auto_number_generation - Ignore auto Purchase order number generation for this Purchase Order. This mandates the Purchase Order number to be entered. Allowed Values true and false.
     */
    export async function main(
      auth: Zoho,
      purchaseorder_id: string,
      organization_id: string | undefined,
      ignore_auto_number_generation: string | undefined,
      body: {
        purchaseorder_number: string;
        date?: string;
        expected_delivery_date?: string;
        reference_number?: string;
        ship_via?: string;
        vendor_id: number;
        salesorder_id?: number;
        is_drop_shipment?: false | true;
        contact_persons?: { contact_person_id?: number }[];
        attention?: string;
        delivery_org_address_id?: number;
        delivery_customer_id?: number;
        notes?: string;
        terms?: string;
        exchange_rate?: number;
        custom_fields?: { customfield_id?: number; value?: string }[];
        line_items: {
          item_id?: number;
          line_item_id?: number;
          account_id?: number;
          name?: string;
          description?: string;
          item_order?: number;
          bcy_rate?: number;
          purchase_rate?: number;
          quantity?: number;
          quantity_received?: number;
          unit?: string;
          item_total?: number;
          tax_id?: number;
          tax_name?: string;
          tax_type?: string;
          tax_percentage?: number;
          image_id?: number;
          image_name?: string;
          image_type?: string;
          reverse_charge_tax_id?: string;
          hsn_or_sac?: string;
          tax_exemption_code?: string;
          location_id?: string;
          tax_exemption_id?: string;
          salesorder_item_id?: number;
        }[];
        location_id?: string;
        gst_treatment?: string;
        tax_treatment?: {};
        gst_no?: string;
        source_of_supply?: string;
        destination_of_supply?: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/purchaseorders/${purchaseorder_id}`,
      );
      for (const [k, v] of [
        ["organization_id", organization_id],
        ["ignore_auto_number_generation", ignore_auto_number_generation],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + 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