Zapier code step calling Hunter API returns an error due to needing a single object. Below is an alternate code snippet:
async function emailRetriever(domainName) {
try {
const response = await fetch('https://api.hunter.io/v2/domain-search?domain=' + domainName + '&api_key=NEW_API_TOKEN');
const result = await response.json();
return result.emails;
} catch (err) {
console.error(err);
}
}
I have faced similar issues when working with the Hunter API in Zapier. In my case, the key was to ensure that the JSON returned by the API matches the expected structure, as API responses can vary depending on input or temporary server states. I resolved this by adding additional checks around the result.emails property and using try/catch blocks to capture non-JSON error responses. It really helped to log the entire response for debugging before accessing nested properties, which prevented runtime errors and saved valuable debugging time.