Edits history of script submission #21202 for ' Create a plan (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a plan
     * Create a new plan.
     */
    export async function main(
      auth: Zoho,
      X_com_zoho_subscriptions_organizationid: string,
      body: {
        plan_code: string;
        name: string;
        recurring_price: number;
        unit?: string;
        interval: number;
        interval_unit?: string;
        billing_cycles?: number;
        trial_period?: number;
        setup_fee?: number;
        setup_fee_account_id?: string;
        tags?: { tag_id?: number; tag_option_id?: number }[];
        custom_fields?: { label?: string; value?: string }[];
        product_id: string;
        product_type?: string;
        hsn_or_sac?: string;
        sat_item_key_code?: string;
        unitkey_code?: string;
        item_tax_preferences?: {
          tax_specification?: string;
          tax_name?: string;
          tax_percentage?: number;
          tax_id?: string;
        }[];
        tax_id?: string;
        is_taxable?: string;
        tax_exemption_id?: string;
        tax_exemption_code?: string;
        description?: string;
        store_markup_description?: string;
        can_charge_setup_fee_immediately?: false | true;
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/billing/v1/plans`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "X-com-zoho-subscriptions-organizationid":
            X_com_zoho_subscriptions_organizationid,
          "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