Edits history of script submission #21225 for ' Create an account (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create an account
     * Creates an account with the given account type.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        account_name?: string;
        account_code?: string;
        account_type?: string;
        currency_id?: string;
        description?: string;
        show_on_dashboard?: false | true;
        can_show_in_ze?: false | true;
        include_in_vat_return?: false | true;
        custom_fields?: { customfield_id?: string; value?: string }[];
        parent_account_id?: string;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/books/v3/chartofaccounts`);
      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