SendInBlue API .NET6 Core Razor Pages in C# AddContactToList catching and throwing error
Asked Answered
A

1

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.

Armin answered 28/3, 2022 at 17:15 Comment(0)
E
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.

Ekaterinburg answered 2/4, 2022 at 12:45 Comment(2)
Ok, was trying not to get the list and hoping for a valid error to present. Guess I will ignore that one.Armin
@Armin 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.Ekaterinburg

© 2022 - 2024 — McMap. All rights reserved.