Edits history of script submission #21190 for ' Create a Sales Return Receive (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a Sales Return Receive
     * Creating a sales return receive to mark the receivable goods as received.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      salesreturn_id: string | undefined,
      body: {
        date?: string;
        line_items: { line_item_id?: {}; quantity?: number }[];
        notes?: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/salesreturnreceives`,
      );
      for (const [k, v] of [
        ["organization_id", organization_id],
        ["salesreturn_id", salesreturn_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