Zapier javascript not working, but Postman code does?!

Hello! I hope someone came across this behavior and can help out!

I have this javascript code I am attempting to execute in Zapier to create a new Taskboard:


fetch ("https://api.monday.com/v2", {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
    'Authorization' : 'YOUR_API_KEY_HERE'
   },
   body: JSON.stringify({
     'query' : query
   })
  })
   .then(res => res.json())
   .then(res => console.log(JSON.stringify(res, null, 2)));

Which come straight from the Monday API documentation: Boards (monday.com)

When I put that code into my Zapier “Run Javascript in Code by Zapier” it complains about not having a output variable, so I add one, i.e. output = ;
But nothing happens. No new board named “my board” is being created in Monday.

However, when I use postman to send the code it works and the “my board” is created:
Create a board - My Workspace (postman.co)

I also tried copying the postman code into Zapier, but that didn’t work either as I am ending up with this error message:
“If you are doing async (with fetch library) you need to use a callback!”

I’m kinda stuck - any ideas?

Thanks!

I was able to figure it out - here the solution hoping it helps somebody else in the future:

Adding the ‘await’ in front of the fetch fixes the ‘you need to use a callback’ error…

let query = 'mutation { create_board (board_name: \"my board\", board_kind: public) {   id }}';

await fetch ("https://api.monday.com/v2", {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
    'Authorization' : inputData.api_key
   },
   body: JSON.stringify({
     'query' : query
   })
  })
   .then(res => res.json())
   .then(res => { return output = (res) });
1 Like