Edits history of script submission #21218 for ' Create a transfer order (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a transfer order
     * Creates a new transfer order in Zoho Inventory.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      ignore_auto_number_generation: string | undefined,
      body: {
        transfer_order_number: string;
        date: string;
        from_location_id: string;
        to_location_id: string;
        line_items: {
          item_id: number;
          name: string;
          description?: string;
          quantity_transfer: number;
          unit?: string;
        }[];
        is_intransit_order?: false | true;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/transferorders`);
      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