sendinblue / APIv3-nodejs-library

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

Issue updating a contact #47

Closed matejicekme closed 5 years ago

matejicekme commented 5 years ago

Hi there,

Got an issue updating a contact, api return an error : "Bad request". Don't know if I miss something or anything else... Here's my code :

const SibApiV3Sdk = require('sib-api-v3-sdk')
const defaultClient = SibApiV3Sdk.ApiClient.instance
const apiKey = defaultClient.authentications['api-key']
apiKey.apiKey = 'xxxxxxxxx'
let toSIDInfos = {
      'NOM': userInfos.lastName,
      'PRENOM': userInfos.firstName
    }
    const apiInstance = new SibApiV3Sdk.ContactsApi()
    let updateContact = new SibApiV3Sdk.UpdateContact()
    updateContact.attributes = toSIDInfos
    updateContact.listIds = [5, 10, 11]
    if (env === 'prod') {
      apiInstance.updateContact(encodeURI(userInfos.email), updateContact).then(function () {
        console.log('SENDINBLUE: API called successfully.')
      }, function (error) {
        console.error('SENDINBLUE_ERROR :' + error)
      })
    }

Of course my userInfos object return right datas.

Any idea ?

Thank you

cappuccio commented 5 years ago

+1 here. I'm having the exact same issue, even if my code looks pretty correct and the request I'm sending looks like the following: email = info%40docendoacademy.eu

updateContact :  {
  "attributes": {
    "field1": "a1v2",
    "field2": "a1v2",
    "field3": "a1v2",
    "field4": "a1v2",
    "field5": "a1v2",
    "field6": "81100",
    "field7": "+393999831122",
    "field8": "+393999831122"
  }
matejicekme commented 5 years ago

@ekta-slit any help with this ? This is the official SendInBlue NodeJS API for customers right ?

Thank you

ekta-slit commented 5 years ago

Hi @matejicekme

Try console.error(error.response.text); in case of error, you will get complete error message. Hope that helps!

Thanks

baleo-it commented 5 years ago

Using code of @matejicekme I get the following error when I try to update a contact:

{
  code: "invalid_parameter",
  message: "Contact already exist"
}

Of course, contact already exists because I'm trying to update!!! I dont understand my error. It seems simpler to use a regular fetch to use your API

baleo-it commented 5 years ago

To fix this issue, I didnt pass email address within attributes key as if email is not different, I get this error message.

achrafha commented 3 years ago

Did you find a solution for this problem ? I'm getting the same error message.

ShubhamChndrvnshi commented 3 years ago

I'm also getting the same issue. I'm trying to update the token field of existing contact. Please help if someone has the solution.

Code :

exports.updateContact = (email,token, firstname,lastname)=>{
    let apiInstance = new SibApiV3Sdk.ContactsApi();

    let identifier = email; 

    let updateContact = new SibApiV3Sdk.UpdateContact(); 
    updateContact.attributes = {"EMAIL":email,"TOKEN": token, "FIRSTNAME": firstname, "LASTNAME": lastname };   
    Object.keys(updateContact.attributes).forEach(key => updateContact.attributes[key] === undefined ? delete updateContact.attributes[key] : {});    
    apiInstance.updateContact(identifier, updateContact).then(function() {
        return "done";
    }, function(error) {
        console.log(error);
        return error;
    });
};

Error:

status: 400, text: '{"code":"invalid_parameter","message":"Contact already exist"}', method: 'PUT', path: '/v3/contacts/shubham%40gmail.com'

shubhamUpadhyayInBlue commented 3 years ago

Hi @ShubhamChndrvnshi

Just a quick check for you: Go to https://my.sendinblue.com/lists/add-attributes in your Sendinblue account and see if the token attribute is created.

If that doesn't help then I request you raise a support ticket from your Sendinblue account so that we can replicate it and check your database configuration.

Happy to help!

ShubhamChndrvnshi commented 3 years ago

Hi @ShubhamChndrvnshi

  • Your code looks fine and I also tried to update an attribute value in my account to find that it is working good white_check_mark

Just a quick check for you: Go to https://my.sendinblue.com/lists/add-attributes in your Sendinblue account and see if the token attribute is created.

If that doesn't help then I request you raise a support ticket from your Sendinblue account so that we can replicate it and check your database configuration.

Happy to help!

Hey shubham,

Thanks for the reply. I've got the solution for above query Just need to add updateContact.type = "type";

After adding above the code works fine for me.