Question

Unable to view response body from succesful HTTP request in coding step

  • 4 October 2023
  • 10 replies
  • 309 views

I am using a code step to make an HTTP request to a private API, but when I test within Zapier, I’m unable to view the response body in the console logs.

The request is working as intended (I’m verifying this from within the API host, which is receiving the request and returning data) and Zapier isn’t throwing an error, the console log is just empty when I try to log the response object. I’m unable to access any of the datapoints in the JSON as well.

I’ve tried this with both javascript and python and I’m having the same issue with both.

The response body is only about 120kb in size, so nowhere near the 6mb limit that I know Zapier imposes, and I’m only testing so far, so no way it’s a rate limit issue. Has anybody run into this before and found a solution?


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

10 replies

Userlevel 7
Badge +14

Hi @Alyssa_B 

Good question.

Have you tried asking ChatGPT for help with the code?

We would need to see detailed screenshots with how your Zap step is configured in order to have enough context.

 

javascript is as follows, redacted to protect API privacy. Like I said above, I’m able to verify from the API endpoint that the request is arriving and is successful, and the received code is 200 when I log the request itself in Zapier, which indicates data was received.

 

const http = require("https");

const url = 'https://www.API_URL.com/path_params_here';

const options = {
'Authorization': 'Basic encrypted_credentials_here',
};

let result = '';
const req = http.request(url, options, (res) => {
console.log(res.statusCode);

res.setEncoding('utf8');
res.on('data', (chunk) => {
result += chunk;
});

res.on('end', () => {
console.log(result);
});
});

req.on('error', (e) => {
console.error(e);
});

req.end();

 

Userlevel 7
Badge +14

@Alyssa_B

Is there a reason you used the Code step instead of the Webhooks app?

 

 

Userlevel 7
Badge +14

@Alyssa_B 

Have you reviewed the available help articles for using the Code app?

https://zapier.com/apps/code/help

Yup, have reviewed all help articles.

Was hoping to avoid the webhook step mainly for time; I need to loop through 6 of these requests and each requires formatting of data for the query and then parsing of the results (while great, I’d much rather handle all of that from one script than from either a script step before/after or using formatter/utilities). Preferable to do it all in one fell swoop, but when I tried the webhook just now it does give me access to my response objects, so I’ll use it for the time being.

Still definitely curious on why I can’t access my response object from the code step, however. Any thoughts there?

Userlevel 7
Badge +14

@Alyssa_B 

You can use the Looping app if you need to iterate: https://zapier.com/apps/looping/help

 

###

 

Still definitely curious on why I can’t access my response object from the code step, however.
Any thoughts there?

I haven’t really tried to troubleshoot.

And may be hard to replicate without knowing the actual API request details you are using.

The request details really shouldn’t be necessary as I’ve already verified that the request is successful several times over; it’s simple JSON that I can view in any other API sandbox (postman, reqbin, etc.) but can’t seem to access in Zapier.

Looping in this case wouldn’t help as each request requires differing formatting that I would have to include steps for anyways to at least get into line-item form for the loop, and each request also requires different parsing that I’d have to make unique paths for.

Userlevel 7
Badge +14

@Alyssa_B

Perhaps try setting the data you want as a variable to output instead of using console.log()?

Tried as well, no dice. Same issue with Python which is really interesting.

Userlevel 7
Badge +14

@Alyssa_B 

You can try opening a ticket with Zapier Support: https://zapier.com/app/get-help