Edits history of script submission #21233 for ' Create an item adjustment (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create an item adjustment
     * Creates a new item adjustment in Zoho Inventory.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        date: string;
        reason: string;
        description?: string;
        reference_number?: string;
        adjustment_type: "quantity";
        location_id?: string;
        line_items: {
          item_id: number;
          name?: string;
          description?: string;
          quantity_adjusted: number;
          item_total?: number;
          unit?: string;
          is_combo_product?: false | true;
          adjustment_account_id?: number;
          adjustment_account_name?: string;
          location_id?: string;
        }[];
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/inventoryadjustments`,
      );
      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: "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