Question

Nesting Trigger Functions


Userlevel 1
Badge

I am working on a trigger where I need to pull data from two API end points. The first endpoint is a contact from a database that retrieves an email address, then to obtain the details for that contact (email) I need to use another end point. once is /Subscriber and the other is /Subsriber/ {email}/ Properties.

 

I am wondering if I can use a variable to obtain all the data in one trigger, as I have is set up in separate triggers right now. 

 

Here is the code for both

Subscriber:

const options = {
url: 'https://edapi.campaigner.com/v1/Subscribers?PageSize=1',
method: 'GET',
headers: {
'Accept': 'application/json',
'X-API-KEY': bundle.authData.ApiKey
},
params: {
'ApiKey': bundle.authData.ApiKey
}
};


return z.request(options).then((response) => {
response.throwForStatus();
const result = z.JSON.parse(response.content);
result.id = result.Items;
return [result];
});

And Subscriber Properties

const options = {
url: `https://edapi.campaigner.com/v1/Subscribers/${bundle.inputData.email_address}/Properties`,
method: 'GET',
headers: {
'Accept': 'application/json',
'X-API-KEY': bundle.authData.ApiKey
},
params: {
'email_address': bundle.inputData.email_address,
'ApiKey': bundle.authData.ApiKey
}
}

return z.request(options).then((response) => {
response.throwForStatus();
const result = z.JSON.parse(response.content);
result.id = result.CustomFields;
return [result];
});

Any help is appreciated. 


9 replies

Userlevel 7
Badge +10

Hi @hank3rd 

You can use Webhooks as action steps to interact with APIs in Zaps: https://zapier.com/apps/webhook/integrations#triggers-and-actions

Userlevel 1
Badge

Hi @hank3rd 

You can use Webhooks as action steps to interact with APIs in Zaps: https://zapier.com/apps/webhook/integrations#triggers-and-actions

I looked at the Webhook option, but is not going to meet this need since the data in the hook is limited. 

Userlevel 7
Badge +10

@hank3rd

The Webhooks should work fine to interact with the desired APIs.

Zap Steps

  1. Trigger: ???
  2. Action: Webhook - API 1 via chosen method (GET/POST/PUT)
  3. Action: Webhook - API 2 (pass in any needed data points from the previous API response)

 

Userlevel 1
Badge

@Troy Tessalone I am already doing that with two triggers, the second one is using the payload from the first. This works, but I am trying to consolidate into one. Even with Webhooks, it seems like it would be more than one trigger and one action, which is more to set up and can be more expensive, no?

Userlevel 7
Badge +9

Hi @hank3rd 

you can combine request in a custom integration however since that is a polling trigger the second request would have to run for each result returned from the first request. Because of that, you may run into time out issues or throttling limits from the API. 

Troy’s suggestion to have your trigger fire for new subscribers and then to follow it up with a custom action or a webhook to retrieve the subscriber properties should work well

Another option might be to specify the additional fields you want to return in the first trigger using the fields parameter https://media.campaigner.com/apidocs/edapi/#BrowseSubscribers

Userlevel 6
Badge +9

I think what you want to have a look at is “dehydration”. https://zapier.github.io/zapier-platform/#dehydration

When doing a polling trigger, the polling request handler will end up processing the same rows over and over again, but only triggering the Zap when we find a new one. We don’t want to make multiple (n+1) requests unless we’ve already determined that the row is new, and that some subsequent step actually needs the data returned from the subsequent API call. That’s what hydration does. You stick that logic to get the additional data in there, and we’ll pass a function handle for it along with the response, instead of doing unnecessary prefetching.  

Userlevel 1
Badge

@Zane  Thank you. I will look into this. I am much of a programmer and this has been the hardest thing for me to do in Zapier. 

 

I believe that I need to poll for a contact (email), then poll for all the custom fields from the “database” call, then pull the details for the contact email to “fill in” the data in the fields while also offering all the fields for mapping. 

 

I might need to find someone to assist on this. 

Userlevel 7
Badge +10

@hank3rd 

Can you please clarify what the trigger app and event would be? (e.g. Campaigner)

From your screenshots, it looks like you are using the Campaigner API.

FYI: The Campaign API supports webhooks: https://knowledge.campaigner.com/article/226-event-and-trigger-reference

Perhaps a Webhook from Campaigner could be used to trigger the Zap, then follow that with Actions steps (Code or Webhooks) to leverage the Campaigner API.

Userlevel 1
Badge

I tried using the web hook, but for contacts, that would only work in certain situations. Added via a form or updated. I am looking to trigger based on addition, no matter the means. 

Use case might be to send new or existing contacts to another platform, maybe a CRM, or SMS platform. 

Reply