Skip to main content
Question

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

  • March 16, 2021
  • 3 replies
  • 3384 views

Forum|alt.badge.img

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

Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • March 16, 2021

Hi @MysterD 

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


GetUWired
Forum|alt.badge.img+12
  • Zapier Solution Partner
  • March 17, 2021

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


Matt_Boyden
Forum|alt.badge.img
  • Zapier Staff
  • June 4, 2021

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