sendinblue / APIv3-python-library

SendinBlue's python library for API v3
MIT License
82 stars 40 forks source link

Can't set a contact attribute of type category #65

Closed NeodarZ closed 3 years ago

NeodarZ commented 3 years ago

Hello,

I'm trying to use this library to use the SendInBlue API but I have encountered a problem. With the following code, slightly modified, I can change all types of attributes of a contact except the ones of the category type, nothing happen. No message saying something is wrong and the value is not saved after I check directly on the web interface.

from __future__ import print_function
import time
import sib_api_v3_sdk
from sib_api_v3_sdk.rest import ApiException
from pprint import pprint

configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = '<REDACTED>'

api_instance = sib_api_v3_sdk.ContactsApi(sib_api_v3_sdk.ApiClient(configuration))
email = 'johnb@example.com'
update_contact = sib_api_v3_sdk.UpdateContact(attributes={'TEST_TEXT': 'foo', 'TEST_CAT': 'Yes'})

try:
    api_instance.update_contact(email, update_contact)
except ApiException as e:
    print("Exception when calling ContactsApi->update_contact: %s\n" % e)

The following image is my configuration for the field TEST_TEXT where I set is as a string, it's ok.

2021-02-26-172443_941x52

And this image is my configuration for the field TEST_CAT where is set the type to category with the configuration: Yes, No, Maybe. I can't understand how to set the value from this library.

2021-02-26-172451_595x542

I'm actually using the last version 7.2.0 if you ask. Maybe I missed something?

NeodarZ commented 3 years ago

Ok I finally found the issue myself, thanks to the week end.

For the prosperity here is the solution: the attribute TEST_CAT of the UpdateContact object need to have the id of an element of the category and not directly the string. I didn't found this in the documentation, this is just a guess from my hand.