Edits history of script submission #21161 for ' Change to Online/Offline mode (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Change to Online/Offline mode
     * Change the status of a particular subscription to Online/Offline mode. If auto_collect is false, the subscription is in Offline mode. If auto_collect is true, the subscription is in Online mode.
     */
    export async function main(
      auth: Zoho,
      subscription_id: string,
      X_com_zoho_subscriptions_organizationid: string,
      body: { auto_collect: {} },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/billing/v1/subscriptions/${subscription_id}/autocollect`,
      );
    
      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