Whenever I run the following curl code, my request to the Mailchimp 3.0 API goes through just fine:
curl --request GET \
--url 'https://us12.api.mailchimp.com/3.0/' \
--user 'anystring:APIKEY'
However, whenever I make a request to the API using Node.js, I receive the following error:
Got error: connect ECONNREFUSED 127.0.0.1:80
I'm assuming I'm missing something or have something mismatched within my .js file, any ideas as to what that might be? Node code is below:
"use strict";
/* globals require, console */
var http = require('http');
var options = {
url: 'https://us12.api.mailchimp.com/3.0/',
headers: {
'Authorization': 'anystring:APIKEY',
'Content-Type': 'application/json',
}
};
http.get(options, (res) => {
console.log(`Got response: ${res.statusCode}`);
// consume response body
res.resume();
}).on('error', (e) => {
console.log(`Got error: ${e.message}`);
});
EDIT: Using uncaught exception returns the following:
Error: connect ECONNREFUSED 127.0.0.1:80
at Object.exports._errnoException (util.js:856:11)
at exports._exceptionWithHostPort (util.js:879:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1053:14)
EDIT 2: Fixed part of it. Was using url
as one of my options instead of host
. Here is the correct code for that portion:
var options = {
host: 'https://us12.api.mailchimp.com/3.0/',
headers: {
'Authorization': 'anystring:APIKEY',
'Content-Type': 'application/json',
}
};
Now I'm receiving the traceback Got response: 400
instead of the data I'm looking to pull.