sendinblue / APIv3-nodejs-library

SendinBlue's API v3 Node.js Library
ISC License
101 stars 47 forks source link

How to add an attribute when create a new contact #80

Closed marco-gentili closed 3 years ago

marco-gentili commented 4 years ago

Hi,

I am struggling to add the attribute propriety while I am creating a new contact.

I would like to add the first name while someone subscribing to the newsletter, how can I do that?

I tried to add the attribute in the options and in the body but it did not work,

const options = {
    method: 'POST',
    headers: {
      "accept": 'application/json',
      "content-type": 'application/json',
      "api-key": 'xkeysib-73505412b....'
    },
    attributes : {
      "FNAME" : input.name
    },
    body: '{"listIds":[2],"updateEnabled":false,"emailBlacklisted":true,"smsBlacklisted":false,"email":'+JSON.stringify(input.email)+'}'
  };

Thank you

shubhamUpadhyayInBlue commented 3 years ago

Hi @marco-gentili

If you have any such query about usage of existing features please raise a support ticket to Sendinblue after logging in to your account here: https://account.sendinblue.com/support. For now, You can use this script to add your attributes while creating a new contact:


let defaultClient = SibApiV3Sdk.ApiClient.instance;

let apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = 'YOUR API KEY';

let apiInstance = new SibApiV3Sdk.ContactsApi();

let createContact = new SibApiV3Sdk.CreateContact();

// adding the attributes while creating a contact
createContact = {
    "attributes": {
        "FIRSTNAME":"John Doe"
    },
    "email":"example@example.com"
};

apiInstance.createContact(createContact).then(function() {
  console.log('API called successfully.');
}, function(error) {
  console.error(error);
});```