Edits history of script submission #21213 for ' Create a tax (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a tax
     * Create a tax which can be associated with an item.
     */
    export async function main(
      auth: Zoho,
      organization_id: string | undefined,
      body: {
        tax_name?: string;
        tax_percentage?: number;
        tax_type?: string;
        tax_factor?: string;
        tax_specific_type?: string;
        tax_authority_name?: string;
        tax_authority_id?: string;
        country_code?: string;
        purchase_tax_expense_account_id?: number;
        is_value_added?: false | true;
        update_draft_invoice?: false | true;
        update_draft_so?: false | true;
        is_editable?: false | true;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/inventory/v1/settings/taxes`);
      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