EDIT: This was a pretty simple error on my side, answer is at the bottom.
Hi,
I have been trying to add tags (multiple) via the REST api. I can do it here:
https://developer.infusionsoft.com/docs/rest/#!/Tags/applyTagToContactIdsUsingPOST
And I can do a single tag without an issue in my Node app, but it errors out when I try to do multiple tags.
I have searched on here and I thought this post (Apply tags to contact Error - REST) should have solved it for me, but I still am getting an error.
Error:
ADD TAG: {“method”:“POST”,“url”:“https://api.infusionsoft.com/crm/rest/v1/contacts/196033/tags",“headers”:{“Authorization”:"Bearer -----------------------”,“Content-Type”:“application/json”},"body":{“tagIds”:[“3179,3303”]},“json”:true}
TAG BODY: (184): [object Object] – Parsing – {“message”:“Input value is invalid: 3179,3303”}
My code looks like this:
function keapCreateContact(keapPhone, keapURL, keapMarketInfo, keapTags, accessToken) {
return new Promise((resolve, reject) => {
const rootUrl = 'https://api.infusionsoft.com/crm/rest/v1';
const authToken = 'Bearer ' + accessToken;
const createContact = {
method: 'PUT',
url: rootUrl + '/contacts',
headers:
{
Authorization: authToken,
'Content-Type': 'application/json'
},
body: {
phone_numbers: [{ field: 'PHONE1', number: keapPhone }],
custom_fields: [{ content: keapURL, id: 183 }, { content: keapMarketInfo, id: 177 }],
duplicate_option: 'Email',
},
json: true
};
request(createContact, function (error, response, body) {
if (error) {
reject('createContactErr');
} else {
if (body.toString().substring(0, 4) === "<h1>") {
reject('invalidToken');
} else {
const contactId = body.id;
const addTag = {
method: 'POST',
url: rootUrl + '/contacts/' + contactId + '/tags',
headers:
{
Authorization: authToken,
'Content-Type': 'application/json'
},
body: { tagIds: [keapTags] },
// body: { tagIds: [2063, 1085] },
json: true
};
console.log("ln 239: ");
console.log(body);
console.log("ADD TAG: " + JSON.stringify(addTag));
request(addTag, function (error, response, body) {
if (error) {
reject('addTagErr');
} else {
resolve('addTagSuccess')
}
});
}
}
});
});
}
I am stumped. Any ideas would be great.
Thanks