Question

Accessing Raw JSON array data using code by zapier - Output help

  • 16 March 2021
  • 3 replies
  • 3088 views

Badge

Hi there, 

I am attempting to retreive some JSON data from an API so I can parse out information to a gsheet. 

The aim is to get raw JSON from the GET request in “code by Zapier”. 

I’ve been successful in getting the JSON via the webhooks by zapier GET zap but I need raw JSON out so I can properly parse out the sections I need. 

This is the API call from a swagger page. 

const options = {
method: 'GET',
headers: {
Accept: 'application/json',
Authorization: 'Bearer 059c02e83998cdeddXXXXXXXXXX'
}
};

fetch('https://api.fsomeurl.co/api/v1.0/menus/75966', options)
.then(response => console.log(response))
.catch(err => console.error(err));

Obvioulsy when I try to use this code in code by zapier I get an error 

 

If you are doing async (with fetch library) you need to use a callback!

 

I am not proficcent in Javascript but I do have a template that I can apply to the raw JSON to parse the information that I require in the next code by zapier step. 

 

Any help in forming the GET request would be greatly appreciated. 

Thanks in advance


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

3 replies

Userlevel 7
Badge +14

Hi @MysterD 

Make sure to reference the available help articles for the Code app: https://zapier.com/apps/code/help

Userlevel 7
Badge +12

@MysterD 

Usually, If I am using fetch in my code block steps. I will format it like so

const request = await fetch(INSERTURL, {
method: "GET",
headers: {
Accept: 'application/json',
Authorization: 'Bearer 059c02e83998cdeddXXXXXXXXXX'
},
});
const data = await request.json();

 

You can then return the data or continue to work with the raw data. 

Userlevel 2
Badge

Hi there @MysterD were you able to get this one figured out? Let us know if you still need help!