Question about making HTTP request with request lib vs axios

This topic was automatically generated from Slack. You can find the original thread here.

Paul : Hi team! I am seeking some assistance POSTing to Zoom’s Incoming Webhook Chatbot (docs here: API Design & Documentation Management | Designing & Building OpenAPIs | Stoplight)

I have no problem using cURL from the command line:
curl 'https://inbots.zoom.us/incoming/hook/xxxxxxxxxxxxx' -X POST -H 'Authorization: XXXXXXXX' -d 'Hello World!'

I have tried with the following but get no response, no errors, nothing. Maybe I should be using Axios? Any suggestions or hints on the best way to form the request would be most appreciated - thank you!

var request = require('request');

var headers = {
'Authorization': 'XXXXXXXXX'
};

var dataString = 'Hello World!';

var options = {
url: 'https://inbots.zoom.us/incoming/hook/xxxxxxxxx',
method: 'POST',
headers: headers,
body: dataString
};

function callback(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
request(options, callback);

Nghia Nguyen : I would suggest axios overall, but that isn’t the problem. If you’re running that code as is, it’s going to have a problem running in the asynchronous function. You need to promisify your callback function and await it.

Nghia Nguyen : see this: Running asynchronous code

Paul : , thank you so much for this. I still have much to learn!

Dylan Sather (Pipedream) : if it helps, we have a guide for making HTTP requests on Pipedream here, as well: Make HTTP Requests with Node.js . +1 to Nghia’s suggestion to use axios - we use that a lot internally and it has a relatively simple interface once you get to know it

Paul : Thanks so much . I did my homework with axios and now have it working and can see how incredibly useful it will be.
Still learning and thanks again to you and the incredible Pipedream team and community.

Nghia Nguyen : no problem , and welcome to the community. This is a great platform to use for a lot of things. Also a reason why I like using axios is because it has interesting other feature packages like axios-retry - npm , which lets you automatically set retry logic that it’ll try to its best ability to execute if HTTPS calls fail for some reason.

Paul : That’s so great ! Thanks for all your helpful tips and advice.