set contact attributes of type "category" with the Sendinblue API

317 views Asked by At

with the sendinblue API I would like to start the double opt-in process for a new contact. That works fine with the example code from the docs:

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

const SibApiV3Sdk = require('sib-api-v3-sdk');
let defaultClient = SibApiV3Sdk.ApiClient.instance;

let apiKey = defaultClient.authentications['api-key'];
apiKey.apiKey = 'YOUR API KEY';

let apiInstance = new SibApiV3Sdk.ContactsApi();

let createDoiContact = new SibApiV3Sdk.CreateDoiContact(); // CreateDoiContact | Values to create the Double opt-in (DOI) contact

createDoiContact.email = "[email protected]";
createDoiContact.attributes = {"FNAME":"John","LNAME":"Doe"};
createDoiContact.includeListIds = [2];
createDoiContact.templateId = 1;
createDoiContact.redirectionUrl = "https://[email protected]";

apiInstance.createDoiContact(createDoiContact).then(function() {
  console.log('API called successfully.');
}, function(error) {
  console.error(error);
});

But I don't know how to fill values for contact attributes of type "category". That are values that can have certain predefined values like a "GENDER", which can have the values "male", "female" and "diverse".

I tried

createDoiContact.attributes = {"GENDER": "male"};

and

createDoiContact.attributes = {"GENDER": [{ label: "male", value: 1 }] };

(I found that in the API doc for updating a contact)

ChatGPT found this:

createDoiContact.attributes = { "GENDER": "male" };

or this:

createDoiContact.attributes = { "GENDER": { "category": "male" } };

But none of that works.

2

There are 2 answers

0
Jochen Kunze On

The sendinblue support gave the answer:

createDoiContact.attributes = { "GENDER": 1 };

where 1 is the number of the possible answer beginning with 1 and so on.

0
Floe On

For anyone struggling to do this with PHP, you have to send the id as a String:

$createDoiContact['attributes'] = array('LANGUAGE' => '1');