Edits history of script submission #22021 for ' Update a transfer order (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update a transfer order
     * Update an existing transfer order from Zoho Inventory.
     */
    export async function main(
      auth: Zoho,
      transfer_order_id: string,
      organization_id: string | undefined,
      body: {
        transfer_order_number: string;
        date: string;
        from_location_id: string;
        to_location_id: string;
        line_items: {
          item_id: number;
          line_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/${transfer_order_id}`,
      );
      for (const [k, v] of [["organization_id", organization_id]]) {
        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