I’m trying to make an HTTP POST request using Zapier’s code functionality. When I use the built-in webhook feature, I get results as comma separated values instead of proper JSON format. The same request works perfectly in Postman and returns JSON as expected.
I converted the request to Node.js code but it runs without returning any data. I’m pretty new to coding so I might be missing something obvious. Can anyone spot what’s wrong?
Here’s my current implementation:
const https = require('https');
const requestOptions = {
method: 'POST',
hostname: 'api.ibmwatson.com',
path: '/tone-analyzer/api/v3/analyze?version=2017-09-21&sentences=false',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer YOUR_TOKEN_HERE',
'Accept-Language': 'en'
}
};
const request = https.request(requestOptions, (response) => {
let dataChunks = [];
response.on('data', (chunk) => {
dataChunks.push(chunk);
});
response.on('end', () => {
const responseData = Buffer.concat(dataChunks);
console.log(responseData.toString());
});
});
const payload = {
text: 'Hello everyone! I am excited to share this amazing news with you all. This project has been incredible to work on and I cannot wait to see the results. Thank you for your continued support and feedback.'
};
request.write(JSON.stringify(payload));
request.end();
return {result: responseData};
Been there with Zapier’s weird quirks. You’re fighting platform limitations instead of using the right tools.
I’ve hit the same wall trying to build complex API workflows in Zapier. Their code steps are clunky, debugging sucks, and you write way more code than you need for basic API calls.
Latenode handles this way better. Build the same Watson tone analysis with visual nodes - no wrestling with Promise callbacks or buffer stuff. The HTTP node auto-parses JSON and you map data straight to the next step.
When things break, you see exactly where without digging through console logs. Switched our team over and saved hours of debugging.
Your Watson integration becomes 3 drag-and-drop nodes instead of 30 lines of buggy code.
The CSV output from Zapier’s webhook is happening because of how the API handles request headers. IBM Watson APIs do this - they return different formats depending on which Accept header takes priority.
Your Node.js issue is a scope problem. responseData only exists inside the callback function, but you’re trying to return it from the module level. That won’t work. Also add error handling for JSON parsing since Watson sometimes sends back errors as plain text.
Ditch the https module headache. Use fetch if it’s available in your Zapier environment, or keep using the webhook step but tweak your Accept headers. Try removing the Accept-Language header - that often fixes Watson’s JSON responses. And double-check your endpoint URL since different Watson API versions return different formats.
Your Node.js code is trying to return responseData outside the response callback scope. That won’t work because HTTP requests are asynchronous - your return statement runs before the response comes back. You need to wrap this in a Promise or use Zapier’s callback pattern.
Wrapping the HTTP request in a Promise lets Zapier handle it properly. The resolve happens inside the response callback where you actually have the data.
Hit this exact Watson API mess 6 months ago and wasted way too much time on Zapier’s webhook weirdness.
Watson’s tone analyzer is ridiculously picky about request formatting. Your headers might look fine, but tiny differences between how Zapier and Postman send requests can trigger their CSV fallback mode.
Your Node.js code does have that async issue people mentioned, but debugging API calls in Zapier’s editor is torture. No real error logs, bizarre timeouts, and endless boilerplate code.
I jumped to Latenode for this stuff. Their HTTP nodes handle Watson’s picky requirements automatically. No wrestling with buffers, promises, or header nonsense.
The visual workflow shows exactly what data moves between steps. When Watson sends back garbage responses, you see it right away instead of playing guessing games with console.log.
Built our whole sentiment analysis pipeline this way. Watson tone analyzer to Slack notifications takes 5 minutes instead of hours debugging code.
yeah, that csv issue with zapier webhooks happens all the time - usually means the api endpoint isn’t sending proper json headers. switch to fetch() instead of the https module. it’s much simpler for zapier code steps and handles json parsing automatically. try const response = await fetch(url, options); const data = await response.json(); return data; - should fix it.
This might be simpler than you think - Watson API ignores accept headers when auth goes wrong. First, double-check your bearer token’s valid. Also try adding &output=json to the query string - usually forces JSON response even when headers fail. For your Node code, you’ve got scope issues like others said, plus you’re not handling content-length properly (Watson needs this).
Had this exact Watson API issue last month. The CSV response is definitely a content negotiation problem on Watson’s end, but there’s an easier workaround than rewriting everything. Stick with Zapier’s webhook step but add Content-Length to your headers and send the request body as raw JSON, not form data. Watson’s API is picky about this. Also try adding ?output=json as a query parameter - some Watson endpoints support this override. For your Node.js version, you’re missing error handling for non-200 responses. Watson sends back 400/401 errors as HTML sometimes, which breaks JSON.parse(). Quick test: hit your Watson endpoint with curl first to see the raw response headers. If you’re getting text/csv in the Content-Type response, Watson thinks you want CSV format regardless of your Accept headers. The query parameter fix usually sorts this out.