API calls in Deluge use the invokeurl statement. The basic syntax:
| // Basic GET request response = invokeurl [ url: “https://api.example.com/endpoint” type: GET connection: “connection_name” ]; // Basic POST request with parameters params = Map(); params.put(“field1”, “value1”); params.put(“field2”, “value2”); response = invokeurl [ url: “https://api.example.com/create” type: POST parameters: params.toString() connection: “connection_name” ]; // POST with JSON body and custom headers headers = Map(); headers.put(“Content-Type”, “application/json”); headers.put(“Authorization”, “Bearer ” + apiToken); response = invokeurl [ url: “https://api.example.com/json-endpoint” type: POST parameters: params.toString() headers: headers ]; |
|---|
For APIs that require authentication — API keys, OAuth tokens, basic auth — Zoho’s Connections feature stores credentials securely and passes them to your API calls without exposing them in your Deluge code. Connections are configured in Setup → Developer Space → Connections.
Create a Connection for the external API you are calling. The Connection stores the authentication credentials. Reference the Connection by name in your invokeurl block using the “connection” parameter. Zoho handles token refreshing for OAuth connections automatically — your Deluge code never needs to manage token lifecycle.
Most modern APIs return JSON responses. Deluge’s invokeurl automatically parses JSON responses into Map objects, so you can read fields directly using .get():
| // Example: call a company data enrichment API // and write results to a Zoho CRM Account record // 1. Build the request accountDomain = “example.com”; // from CRM account record response = invokeurl [ url: “https://api.clearbit.com/v2/companies/find?domain=” + accountDomain type: GET connection: “clearbit_connection” ]; // 2. Parse the response // response is already a Map if the API returns JSON companyName = response.get(“name”); employeeCount = response.get(“metrics”).get(“employees”); industry = response.get(“category”).get(“industry”); linkedInUrl = response.get(“linkedin”).get(“handle”); // 3. Write results to the CRM account record updateMap = Map(); updateMap.put(“Enriched_Employee_Count__c”, employeeCount); updateMap.put(“Enriched_Industry__c”, industry); updateMap.put(“LinkedIn_URL__c”, “https://linkedin.com/company/” + linkedInUrl); zoho.crm.updateRecord(“Accounts”, accountId, updateMap); |
|---|
API calls fail — the external service is down, the request is malformed, the rate limit is exceeded. Every production Deluge API call should include error handling:
| // Robust API call with error handling try { response = invokeurl [ url: “https://api.example.com/data” type: GET connection: “my_connection” ]; // Check for an error field in the response if(response.containsKey(“error”)) { info “API error: ” + response.get(“error”).get(“message”); return; // exit the function gracefully } // Process successful response data = response.get(“data”); info “API call successful. Records returned: ” + data.size(); } catch (e) { info “invokeurl failed: ” + e.get(“message”); // Optionally: create an error log record, send an alert email } |
|---|
External APIs have rate limits — a maximum number of requests per second or per minute. A Deluge scheduled function that calls an external API for every record in a large dataset can exceed the API’s rate limit, causing requests to fail. For batch operations, add a delay between API calls or process records in smaller batches:
For the full API integration architecture — including bi-directional syncs, webhook patterns and the decision between Deluge API calls and the Zoho REST API — see the Zoho API integrations hub and the integration methods comparison guide.
| // Process records with rate limit awareness for each record in records { // Call the external API for this record response = invokeurl [url: apiUrl type: GET connection: “my_conn”]; // Process response… // Add a brief delay between calls if needed // Note: Deluge does not have a sleep() function. // For strict rate limiting, use a smaller batch size // and schedule multiple function runs throughout the day. } |
|---|
Can Zoho Deluge call any external API?
How does authentication work for API calls in Zoho Deluge?
What happens if an API call fails in a Deluge script?
Are there rate limits on API calls from Zoho Deluge scripts?
Can ABR build Deluge scripts with external API integrations for us?