The api-pagination Deluge script enables you to handle pagination when calling an API. The Zoho CRM API is used here, but you can modify this to work with any API.
Many APIs (including the Zoho CRM API) limit the number of results you may receive per API response page, but there is still a need to retrieve additional records from the API. When calling an API you generally have the option to specify the number of results per page (though limited) and the specific page of results. For example in the query parameters of the API URL, you may specify: “?per_page=200&page=1”
Deluge does not have native support for API pagination or while
loops, which is problematic. This script enables the ability to paginate API requests in Deluge.
Before you can use this script with Zoho CRM, you must specify the following in the script:
connection
in the invokeurl
method.zohoCrmModule
variable.perPageLimit
variable.In order to call the Zoho CRM API within a Deluge Script, you must first create a connection to it.
Since Deluge doesn’t have a native while
loop, we emulate its behavior. A for each
iteration is performed over the pageIterationList
variable. Within this block, we will rely on a boolean iterationComplete
to determine whether we will continue to execute our API calls. The outer loop will technically continue to iterate, but will not be executing any internal code, thus allowing us to control iterations.
Important: This iteration list contains values from 1 to a number significantly greater than the expected count of result pages. If you don’t want to type this list by hand, see the Pinetools Number List Generator.
The API request will then be executed and manipulated into the records
variable which will only contain the current requested records. The records
will be subsequently added to the allRecords
list which will contain the accumulation of all API requests.
Since the for each
process is emulating a while
loop we need set our iterationComplete
variable. We will set iterationComplete
to true
only when the the number of results on a page is less than our APIs per_page
limit.
Click here to copy these scripts. For more Zoho-wizardry, check out our GitHub page.
When scripting, ask yourself this question – will this value ever be null? If it’s a yes, that’s a place for a null check! Here are 3 tips and best practices to help you kickstart the habit....
Learn to create a customized inventory report with Zoho Analytics. This tutorial contains a link to our GitHub page for SQL code that will help with your table creations....
How nice would it be if you could, at the press of a button, send clients an email w/a Zoho Books invoice? Replete with “Pay Now” buttons that link to PayPal/Stripe/other payment gateways?...
Whether you work primarily out of CRM or the Zoho Finance Suite, you can use Analytics to build commissions dashboards. This involves some fairly simple SQL code....
If you are an inventory manager, this blog post could change your life. If you are not, it will at least teach you how to build some wicked inventory tracking for your business....
Convert fields, related activities, attachments, notes and more from one record to another across modules via custom function....