Edits history of script submission #21188 for ' Create a Sales Order (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a Sales Order
     * Creates a new Sales Order in Zoho Inventory. Description about extra parameter ignore_auto_number_generation - Ignore auto sales order number generation for this sales order. This mandates the Sales Order number to be entered. Allowed Values true and false.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      ignore_auto_number_generation: string | undefined,
      body: {
        customer_id: number;
        salesorder_number: string;
        date?: string;
        shipment_date?: string;
        custom_fields?: {
          custom_field_id?: number;
          index?: number;
          label?: string;
          value?: string;
        }[];
        reference_number?: string;
        location_id?: string;
        line_items: {
          item_id?: number;
          name?: string;
          description?: string;
          rate?: number;
          quantity?: number;
          unit?: string;
          tax_id?: number;
          tds_tax_id?: string;
          tax_name?: string;
          tax_type?: string;
          tax_percentage?: number;
          item_total?: number;
          location_id?: string;
          hsn_or_sac?: string;
          sat_item_key_code?: string;
          unitkey_code?: string;
        }[];
        notes?: string;
        terms?: string;
        discount?: number;
        is_discount_before_tax?: false | true;
        discount_type?: string;
        shipping_charge?: number;
        delivery_method?: string;
        adjustment?: number;
        pricebook_id?: string;
        salesperson_id?: string;
        adjustment_description?: string;
        is_inclusive_tax?: false | true;
        exchange_rate?: number;
        template_id?: number;
        documents?: {
          can_send_in_mail?: false | true;
          file_name?: string;
          file_type?: string;
          file_size_formatted?: string;
          attachment_order?: number;
          document_id?: number;
          file_size?: number;
        }[];
        billing_address_id?: number;
        shipping_address_id?: number;
        place_of_supply?: string;
        gst_treatment?: string;
        gst_no?: string;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/salesorders`);
      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: "POST",
        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