For this tutorial in video form, click here

In this article, we’ll show you how to integrate with Zoho Subscriptions from Zoho Creator. The Zoho Subscriptions API is quite nice. The documentation is also clear as day. They make it easy to know what to do.

The Process

If we check the documents, you’ll see that we have to POST some data to create the subscription.

You need to give it an AuthToken and Organization ID which you can get from inside Zoho Subscriptions. After that, we give it the customer data in addition to the plan details and any custom details we want to add.

This is what it looks like in Zoho Creator:

At the top, we have ORGANISATION_ID and AUTH_TOKEN.

Below that, we’re setting up a map that will update customers. You can see this documentation in the API under Customers>Update a customer.

To update a customer, we just need to know what the ID is for the existing customer.

Then we pass it a JSON payload with keys representing the fields that we want to update. In our case, we want to update the portal. it’s not enabled for customers, and we need our customers to be able to access the portal.

Here we can see it in the API.

Further down the documentation, we can see what variables are supported:

In our function, you can see we’re setting up a map that has is_portal_enabled set to true. Then we’re directly using the integration task for Zoho Subscriptions. You can do zoho.subscriptions.create, zoho.subscriptions.update, or zoho.subscriptions.retrieve. That will then allow you to access the API.

In some cases, using the integration task can prove rather difficult. When setting up the second part here, we needed to be able to add a list of add-ons for the subscription, and the default integration task didn’t support that. For that reason, we went with the postURL task, which directly does a POST request. The rest of it is pretty similar though.

The subscription is set up with a base plan followed by add-ons. We’re starting out with some internet add-ons.

Notice how we have a form (from Zoho Creator). We’re then going through each of the line items there and then add an add-on as a map. We need to convert it to a string first. That will turn it into JSON format. As a map, it looks like this:

But in order to pass through the API , it has to look more like this:

The latter is a stringified version. By doing toString, it ensures that the quotation marks are correctly escaped and other good stuff like that.You just have to remember, this is the process: if you’re adding a list of add-ons to the plan, you need to initially create a map, and then you convert them to string.

Finally, we ‘re converting them to a JSON list, which is going to create the array that the API accepts.

In the documentation under Subscriptions>Create a Subscription, we can scroll far down in the example and see that it’s an array. By calling toJSONList, it’s converting them into an array.

For this tutorial in video form, click here