sendinblue / APIv3-java-library

SendinBlue's API v3 Java Library
MIT License
42 stars 12 forks source link

'createContact' with updateEnabled doesn't fallback to the updateContact behavior #11

Closed JeanDamien closed 3 years ago

JeanDamien commented 5 years ago

Hi, I'm trying to update a contact informations and add it to a new list. I don't know if this contact is already in my contact list so I'm using 'createContact' with updateEnabled: true (https://github.com/sendinblue/APIv3-php-library/issues/29) otherwise, updateContact will failed with a 'Contact does not exist' message.

The documentation said: listIds: Ids of the lists to add the contact to so I'm expecting the user to be add to the lists and not set the lists of the contact

Problem

If the contact exists and is already in a list, the contact's listIds is override.

Example:

Initial contact informations:

{
  "email": "jtx@sendinblue.com",
  "id": 1,
  "emailBlacklisted": false,
  "smsBlacklisted": false,
  "attributes": {
  },
  "listIds": [
    12
  ],
  "statistics": {}
}

I'm using something like:

CreateContact createContact = new CreateContact();
createContact.setEmail("jtx@sendinblue.com");
createContact.setListIds(Arrays.asList(24L));
createContact.setUpdateEnabled(true);

contactsApi.createContact(createContact);

Current behavior:

{
  "email": "jtx@sendinblue.com",
  "id": 1,
  "emailBlacklisted": false,
  "smsBlacklisted": false,
  "attributes": {
  },
  "listIds": [
    24
  ],
  "statistics": {}
}

Expected behavior:

{
  "email": "jtx@sendinblue.com",
  "id": 1,
  "emailBlacklisted": false,
  "smsBlacklisted": false,
  "attributes": {
  },
  "listIds": [
    12,
    24
  ],
  "statistics": {}
}

Am I missing something ?

Thanks!

mig-visiblee commented 5 years ago

+1. Got the same issue and found out that createContact() with updateEnabled actually overrides all information about the existing contact. updateEnabled here seems to be merely a synonym for "don't fail if already exists".

It also replaces all contact attributes information with those you send (meaning you cannot use this endpoint to merely change a single property)

We had to call getContactDetails() (which is a shame because it's a big endpoint) to make sure contact exists before calling addContactToList()

MDev22 commented 4 years ago

Same problem here. The double call to check if contact exist is a very useless call.

amitsendinblue commented 3 years ago

Please try the latest release