Question

How to make two api calls

  • 27 June 2022
  • 4 replies
  • 401 views

Badge

I need to make two api calls in single action. how can I do that. anybody know kindly write answer.


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Userlevel 7
Badge +14

Hi @Nagamanickam 

Good question.

Please elaborate more about which app API requests you are trying to make in order for us to have more context, thanks.

Userlevel 7
Badge +12

@Nagamanickam 
If you are building your own custom action (developer.zapier.com) or using a code block then you can make as many calls as you want until you hit time out limits... code blocks are limited to 10 seconds on paid accounts & custom actions time out after 30. 

@GetUWired
We are building our own custom action by using a code block. In our case, we need to make a request to find users by using their email addresses and then create a meeting with those users.

Code block doesn’t allow us to write async & await code. It would be helpful if you could share a sample code or document on how to make multiple API requests in a custom action in the code block. 

   

Userlevel 7
Badge +12

A code block allows you to use fetch.. usually i write something along the lines of:

const request = await fetch(url,options);
const data = await request.json

When i am in a code block. 

When building a custom action in developer.zapier.com you can switch to code mode and use z.request 

 

//first request
return z.request(options)
  .then((response) => {
    response.throwForStatus();

    const results = response.json;
//results is what is stored in the json response

//you can then use data to make another call.
return z.request(moreOptions)
  .then((secondResponse) => {
    secondResponse.throwForStatus();
const secondResultSet = secondResponse.json;

return secondResultSet
})
})