Reputation: 61
I'm using mailchimp-api-v3 for nodejs. I'm currently trying to update a user's tag but sometimes this error pops up and I have no idea what it means. I searched around but it doesn't seem like a lot of devs have encountered it.
Any suggestions are welcomed.
try {
await mailchimp.post('/lists/' + listIDUsers + '/members/' + crypto.createHash('md5').update(profileSnap.val().email.toLowerCase()).digest("hex") + '/tags', {
tags: [{name: "traveler", status: "active"}]
});
} catch (error) {
if (error.status === 404) {
await mailchimp.post('/lists/' + listIDUsers + '/members', {
email_address: profileSnap.val().email,
status: 'subscribed',
merge_fields: {
"FNAME": profileSnap.val().firstName,
"LNAME": profileSnap.val().lastName,
"UID": uid,
"EMAIL": profileSnap.val().email
},
tags: [{name: "traveler", status: "active"}]
});
} else {
console.log("Issue for: " + uid);
console.log(error);
}
The error:
Error: Expected argument of type "string", "stdClass" given
at Request._callback (/srv/node_modules/mailchimp-api-v3/index.js:506:30)
at Request.self.callback (/srv/node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/srv/node_modules/request/request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (/srv/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickDomainCallback (internal/process/next_tick.js:219:9)
Upvotes: 3
Views: 1738
Reputation: 61
Okay, I've decided to go ahead and reach out to Mailchimp since this question has been left unanswered for a few days! They got back to me stating that the reason I'm getting the error above is that because I'm trying to set a tag for a subscriber right after adding the subscriber so the system wasn’t able to successfully add the tag because the subscriber hashed id wasn’t quiet created yet.
So all I needed was the following line of code to have my function wait 10 seconds before setting the tag.
await new Promise(resolve => setTimeout(resolve, 10000));
await mailchimp.post('/lists/' + listIDUsers + '/members/' + crypto.createHash('md5').update(profileSnap.val().email.toLowerCase()).digest("hex") + '/tags', {
tags: [{name: "traveler", status: "active"}]
});
Upvotes: 3