Hey everyone! I’m trying to figure out how to grab info from two different API endpoints in one Zapier trigger. Right now I’ve got it set up as separate triggers, but I’m hoping there’s a way to combine them.
Basically, I need to get a contact’s email from one endpoint (/Subscriber) and then use that email to fetch more details from another endpoint (/Subscriber/{email}/Properties). Is there a trick to doing this all in one go?
Here’s a simplified version of what I’m working with:
// First endpoint
const getSubscriber = async () => {
const response = await fetch('https://api.example.com/Subscriber?limit=1', {
headers: { 'API-Key': 'your-api-key' }
});
return response.json();
};
// Second endpoint
const getProperties = async (email) => {
const response = await fetch(`https://api.example.com/Subscriber/${email}/Properties`, {
headers: { 'API-Key': 'your-api-key' }
});
return response.json();
};
Any ideas on how to combine these into a single trigger? Thanks in advance for your help!
I’ve faced a similar challenge in my Zapier workflows, and I found a solution that might work for you. Instead of trying to combine the API calls into a single trigger, you can use Zapier’s ‘Code’ action to make both API requests sequentially.
Here’s how I approached it:
- Set up your initial trigger as usual.
- Add a ‘Code’ action step.
- In the Code step, use JavaScript to make both API calls.
- Parse and combine the results as needed.
The Code step would look something like this:
const apiKey = inputData.apiKey;
const baseUrl = 'https://api.example.com';
const getSubscriber = async () => {
const response = await fetch(`${baseUrl}/Subscriber?limit=1`, {
headers: { 'API-Key': apiKey }
});
return response.json();
};
const getProperties = async (email) => {
const response = await fetch(`${baseUrl}/Subscriber/${email}/Properties`, {
headers: { 'API-Key': apiKey }
});
return response.json();
};
const subscriber = await getSubscriber();
const email = subscriber.email;
const properties = await getProperties(email);
return {
subscriber: subscriber,
properties: properties
};
This approach has worked well for me in similar situations. It’s more flexible than trying to combine triggers and allows you to handle the data exactly as you need.
hey sophia, i’ve dealt with this before. try using zapier’s webhooks. set up a webhook trigger, then use the code action to make both API calls. something like:
const sub = await fetch('endpoint1');
const email = sub.json().email;
const props = await fetch(`endpoint2/${email}`);
return {sub, props};
this way u get all the data in one go. good luck!
While combining API calls in a single Zapier trigger isn’t directly possible, there’s a workaround using Zapier’s ‘Paths’ feature that might suit your needs. Here’s how you could approach it:
- Set up your initial trigger to fetch the subscriber data.
- Use a ‘Path’ step to create two branches.
- In one branch, use an ‘API’ action to call the /Subscriber/{email}/Properties endpoint.
- In the other branch, set up any actions you need with just the subscriber data.
- Use a ‘Merge Paths’ step to combine the results.
This method allows you to fetch both sets of data within a single Zap, effectively creating a combined trigger. It’s more maintainable than complex code solutions and gives you flexibility to handle each API response separately if needed.