0
votes

I'm working with Mailchimp API in NodeJS and fail to add a member to a list.

Here my snippet.js

var username = "&&";
var password = "&&-us&&";
var auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
var url = "https://us-&&.api.mailchimp.com/3.0/lists/[listId]/members";
var json = { "email_address":"test@ŧest.com", 
"status":"pending", 
"merge_fields":{ "FNAME" : "newuser", 
                 "LNAME" : "happy" }
            }
request({ url, json: json, method: 'POST', 
          headers: { 'Content-Type': 'application/json', 
                     'Authorization': 'apikey ' + password }
         }, function(err, res, body){
                 if(err){ 
                        return console.log("err:", err) 
                } 
                   console.log("connection succeed"); console.log("res: ", res) 
});

​ My console returns me :

err: { Error: getaddrinfo ENOTFOUND us-`&&.api.mailchimp.com us-18.api.mailchimp.com:443

at errnoException (dns.js:50:10)

at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)

code: 'ENOTFOUND',

errno: 'ENOTFOUND',

syscall: 'getaddrinfo',

hostname: 'us-&&.api.mailchimp.com',

host: 'us-&&.api.mailchimp.com',

port: 443 }

​I can't figure out what is wrong, if anybody has an hint, would be great.

1
Is us-&&.api.mailchimp.com valid url? - KarlR
getaddrinfo ENOTFOUND means client was not able to connect to given address, so for sure address above with && is wrong. That is why You got an error. - KarlR
okay I have double checked my url and seems there was a typo there, now my console returns me "The requested resource could not be found." again it seems to me that all the fields are here but I go for a double checking - Webwoman
How do You pass listId parameter - KarlR

1 Answers

0
votes

The valid url would be something like https://serverName.api.mailchimp.com/3.0/lists/listID.

You need to replace the following two in the URL for it to work:

  1. serverName - You have to generate your own specific API key which will look something like this: #########################-us2. You have to replace serverName with us2 in the url in this case.
  2. listID - You have to generate a specific list id on mailchimp from which you will get a listID which you will have to replace in the url, say #######.

So, the final URL will look something like this https://us2.api.mailchimp.com/3.0/lists/#######.