6

I a using the exact code here https://developers.sendinblue.com/reference/addcontacttolist-1 to add a user to a list. It all works, user is created/updated (if exists) then the user is added to the list. However, when adding to the list it throws an error.

Error calling AddContactToList: {"code":"invalid_parameter","message":"Contact already in list and/or does not exist"}

enter image description here

Their code shows a display result in JSON which will never get hit because it throws at the Add method.

Zippy
  • 455
  • 1
  • 11
  • 25

1 Answers1

3

The error is straight-forward. The contact is already in the list and the API enforces uniqueness.

You can get the contacts that are already in the list via getContactsFromList

https://developers.sendinblue.com/reference/getcontactsfromlist

or contact details via getContactInfo:

https://developers.sendinblue.com/reference/getcontactinfo-1

So, you will need to check whether the contact is already in the list. If so, then don't add it. Otherwise, you can add it without problems.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • 1
    Ok, was trying not to get the list and hoping for a valid error to present. Guess I will ignore that one. – Zippy Apr 02 '22 at 23:51
  • 1
    @Zippy you can decide to not handle this error, but you will need to make sure that in your `catch` clause you handle other errors, so, it is advisable to change `Exception e` to have a more specific type, so other exceptions will not be ignored. – Lajos Arpad Apr 03 '22 at 10:54