Using the Chargebee API to Save Time With Parabola

July 20, 2021

If you use Chargebee to handle recurring subscription payments from your customers, you might encounter a scenario where you need to modify dozens, hundreds, or even thousands of subscriptions.

For example, you might decide to give every one of your customers a temporary pause on their billing. You might want to cancel hundreds of subscriptions. Or, you might want to move your customers from one plan to another.

You could manually do this inside of Chargebee, but it would be a slow, tedious process.

That's why you should use their API. Using their API can replace hundreds of manual clicks by you with a program that will do your work for you.

To update every customer subscription manually in Chargebee will take you 10-15 seconds per customer.

At that rate, it will take about 2 hours and 45 minutes to update 1,000 customer subscriptions. This automation will save you that time.

If you're not a developer, the easiest way to use their API is through Parabola.

You can use Chargebee's API to accomplish many tasks related to managing your customer billing, but in this article, I'll show you how to use Chargebee's API to change the next billing date for hundreds of customers at once.

Overview

Here is an overview of what we're building in Parabola:

1. First, we'll pull in all of our subscriptions from Chargebee, by using their API.

2. The Expand JSON step makes the JSON objects readable as a table.

3. The filter step will filter out any non-active subscriptions.

4. The last step will use an API endpoint to modify the subscriptions by changing their date of the end of their term (documentation here). We will pass a new end date to each subscription through the endpoint itself.

Detailed build instructions

First, open one tab with the Chargebee API docs and another one with a blank flow in Parabola.

In Parabola, start by dragging in a "Pull from API" step.

The API docs say that the endpoint URL structure is

https://{site}.chargebee.com/api/v2/subscriptions

Replace {site} with your site (listed in the top left of your account when you are logged into your main dashboard).

Here's what your Pull from API step should look like right now:

At this point, you'll get an error on this step, because we haven't authenticated our Chargebee API request yet.

Chargebee API Authentication and Keys

The docs for authentication tell us that we need to get an API key from the web client console. Here is where you create those keys:

To make modifications to your customer data using Parabola, you'll need to create a full access key.

Give it a name like "Parabola key". The actual key itself is the string of characters that starts with "live_". Copy that and save it somewhere safe.

Back in Parabola, we'll authenticate in the Pull from API step. Under the authentication section of the step, choose "Username and Password" as the Authentication Type. Set the username as your live API key and leave the password blank.

Here is what your setup should look like at this point:

Next, we'll connect the data of this step to an "Expand JSON' step.

You'll notice at this point that you only get 10 rows of data. That's because, by default, Chargebee limits the data to 10 subscriptions.

To get more, we need to go back to our pull from API step and add the limit parameter.

Our endpoint for the Pull from API step should now be:

https://{site}.chargebee.com/api/v2/subscriptions?limit=100

 

If you have more than 100 subscriptions, you'll see the "next_offset" column. That column gives you values to use the next time you run the step or the flow so that you can see the next 100 transactions. We'll come back to this.

If you go back to the Expand JSON step, you should now see 100 rows (assuming you have at least 100 subscriptions).

Our next step in Parabola is a filter to select only those subscriptions that are still active (no point in updating a cancelled subscription).

Lastly, we'll set up the "Send to API" step in Parabola, which will update each subscription with a new end date for their current term, changing the date of when they will next be billed.

The endpoint for this is:

https://{site}.chargebee.com/api/v2/subscriptions/{list subscription id}/change_term_end?term_ends_at={updated-term-end-time}

Replace {site} with your site in the endpoint.

The variable {list subscription id} will be replaced automatically by Parabola with the ID of the customer who's subscription you are updating.

You will need to change the {updated-term-end-time} to a unix value of the new date you'd like your customers terms to end on. You can convert a date to unix time here.

You'll need to authenticate in this step using the same method as the "Pull from API" step.

At this point, we are set up to update the end term of 100 subscriptions in Chargebee at once.

After you run your flow once, you'll want to change the "Pull from API" step and add an offset parameter, so that you can access a batch of the next 100 subscriptions in your Chargebee account.

You are taking the value from the "next_offset" column returned by your first time accessing the API and putting that value in an "offset" parameter. This is described in more detail here.

Your Pull from API step will now look like this:

Notice that the "next_offset" column has a new value. That's the value you use to access the next 100 records of your customer subscriptions (and so on and so forth).

But what if you don't want to have to manually update the offset parameter for each 100 subscriptions?

There is a workaround involving the "Enrich with API" step in Parabola, but I won't muddy the waters by going into it here. DM or email me if you'd like me to explain.

Conclusion

This has been a rundown on how to use the Chargebee API to update hundreds of customer subscriptions in batches.

Before running your flow, I'd recommend adding a Limit or Filter step to your flow and testing out your set up, to make sure that you have everything set up correctly.

Got any questions on how to build this or other automations? Send me an email or DM.

ūüĎč Looking to no-code freelance?

I'm putting together a list of companies that could use some help.

The list is full of detailed info, but I don't want these companies to get overwhelmed by pitches, so only a limited number of freelancers will get access.

Put in your email below and I'll send it your way.

3 left at free price tier. Next price: $15