Hi Companies House Support Team,
I hope this message finds you well.
We are currently encountering an issue with our Deluge Zoho’s Proprietary language, which is designed to fetch company data from Companies House and create corresponding leads in Zoho CRM. Despite there being more than 1000 records available, we are only able to retrieve 20 records. Below are the three sets of Deluge scripts we are using:
**Script 1: Fetch Companies from Companies House
api_key = “bdf1c306-d857-413a-bfd5-a74ee3c29fbe”;
url =“https://api.company-information.service.gov.uk/advanced-search/companies”;
headers = Map();
headers.put(“Authorization”,"Basic " + zoho.encryption.base64Encode(api_key + “:”));
response = getUrl(url,headers);
response_map = response.toMap();
info response_map;
if(response_map.containsKey(“company_name”)) {
company_data = response_map;
info company_data;
lead_data = Map();
lead_data.put(“Company”,company_data.get(“company_name”));
lead_data.put(“Last_Name”,company_data.get(“company_name”));
lead_data.put(“Status”,company_data.get(“company_status”));
lead_data.put(“Date_of_Creation”,company_data.get(“date_of_creation”));
lead_data.put(“Phone”,company_data.get(“person_number”));
lead_data.put(“Lead_Source”,“CH”);
info "Lead Data: " + lead_data;
createResponse = zoho.crm.createRecord(“Leads”,lead_data);
info createResponse;
if(createResponse.get(“status”) == “success”) {
info “Lead created successfully”;
} else {
info “Failed to create lead”;
info "Detailed response: " + createResponse;
}
} else {
info “Failed to fetch company data”;
info response_map;
}
return “”;
**Script 2: Remove Duplicates and Fetch Companies by Type
api_key = “bdf1c306-d857-413a-bfd5-a74ee3c29fbe”;
url =“https://api.company-information.service.gov.uk/advanced-search/companies?company_type=EEIG”;
headers = Map();
headers.put(“Authorization”,"Basic " + zoho.encryption.base64Encode(api_key + “:”));
response = getUrl(url,headers);
response_map = response.toMap();
info response_map;
if(response_map.containsKey(“company_name”)) {
company_data = response_map;
info company_data;
lead_data = Map();
lead_data.put(“Company”,company_data.get(“company_name”));
lead_data.put(“Last_Name”,company_data.get(“company_name”));
lead_data.put(“Status”,company_data.get(“company_status”));
lead_data.put(“Date_of_Creation”,company_data.get(“date_of_creation”));
lead_data.put(“Phone”,company_data.get(“person_number”));
lead_data.put(“Lead_Source”,“CH”);
info "Lead Data: " + lead_data;
createResponse = zoho.crm.createRecord(“Leads”,lead_data);
info createResponse;
if(createResponse.get(“status”) == “success”) {
info “Lead created successfully”;
} else {
info “Failed to create lead”;
info "Detailed response: " + createResponse;
}
} else {
info “Failed to fetch company data”;
info response_map;
}
return “”;
Script 3: Remove Duplicates and Fetch Company Details
api_key = “bdf1c306-d857-413a-bfd5-a74ee3c29fbe”;
search_url = “https://api.company-information.service.gov.uk/advanced-search/companies”;
headers = Map();
headers.put(“Authorization”,"Basic " + zoho.encryption.base64Encode(api_key + “:”));
search_response = getUrl(search_url,headers);
try {
search_response_map = search_response.toMap();
info search_response_map;
if(search_response_map.containsKey(“items”)) {
companies = search_response_map.get(“items”);
for each company in companies {
company_number = company.get(“company_number”);
info "Fetching details for company number: " + company_number;
search_criteria = “(Company_Number:equals:” + company_number + “)”;
duplicate_check_response = zoho.crm.searchRecords(“Leads”,search_criteria);
if(duplicate_check_response.size() == 0) {
company_url = “https://api.company-information.service.gov.uk/company/” + company_number;
company_response = getUrl(company_url,headers);
try {
company_data = company_response.toMap();
info company_data;
if(company_data.containsKey(“company_name”)) {
lead_data = Map();
lead_data.put(“Company”,company_data.get(“company_name”));
lead_data.put(“Last_Name”,company_data.get(“company_name”));
lead_data.put(“Company_Number”,company_data.get(“company_number”));
lead_data.put(“Lead_Source”,“CH”);
createResponse = zoho.crm.createRecord(“Leads”,lead_data);
info createResponse;
if(createResponse.get(“status”) == “success”) {
info "Lead created successfully for company number: " + company_number;
} else {
info "Failed to create lead for company number: " + company_number;
info "Detailed response: " + createResponse;
}
} else {
info "Failed to fetch detailed company data for company number: " + company_number;
info company_data;
}
} catch (e) {
info "Error converting company response to map: " + e.toString();
info "Response content: " + company_response;
}
} else {
info "Duplicate lead found for company number: " + company_number;
}
}
} else {
info “No companies found in the specified date range.”;
info search_response_map;
}
} catch (e) {
info "Error converting search response to map: " + e.toString();
info "Response content: " + search_response;
}
return “”;
Our main concern is the limitation of fetching only 20 records despite the availability of over 1000 records. We suspect that there might be a limitation related to the foreach loop or pagination in the API responses.We are currently integrating your API to fetch data and need to implement pagination in our requests. This is to ensure that all fetched records can be processed and created in Zoho CRM, where there are no limitations on the number of records we can create
Could you please assist us in identifying if there is a limit on the foreach loop or pagination issue? If so, can you provide a solution or workaround to fetch all the available records?Could you please provide guidance on how to define pagination in your API calls? We would like to set a limit on the number of records fetched per request to manage the data efficiently.
If additional information is needed, please let me know, and I will be happy to provide it.
Thank you for your prompt attention to this matter.