Skip to main content
Question

How to make two api calls


Forum|alt.badge.img

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

Did this topic help you find an answer to your question?
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

Troy Tessalone
Forum|alt.badge.img+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.


GetUWired
Forum|alt.badge.img+12
  • Zapier Expert
  • 1030 replies
  • June 27, 2022

@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. 

   


GetUWired
Forum|alt.badge.img+12
  • Zapier Expert
  • 1030 replies
  • July 6, 2022

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
       })
    })