Edits history of script submission #21142 for ' Buy one-time addon (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Buy one-time addon
     * Include a one-time addon in the subscription.
     */
    export async function main(
      auth: Zoho,
      subscription_id: string,
      X_com_zoho_subscriptions_organizationid: string,
      body: {
        addons: {
          addon_code: string;
          quantity?: number;
          tags?: { tag_id?: number; tag_option_id?: number }[];
          item_custom_fields?: { label?: string; value?: string }[];
          price?: number;
          tax_id: {};
          tax_exemption_id?: {};
          tax_exemption_code?: {};
          product_type?: string;
        }[];
        exchange_rate?: never;
        coupon_code?: {};
        add_to_unbilled_charges?: false | true;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/billing/v1/subscriptions/${subscription_id}/buyonetimeaddon`,
      );
    
      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