Create contact attribute

Log in to see full request history

Code Examples

You can use as reference the code below to implement this call in your preferred language.
Check all our official API clients here

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.AttributesApi(); let attributeCategory = "category"; let attributeName = "levelOfExpertise"; let createAttribute = new SibApiV3Sdk.CreateAttribute(); createAttribute.enumeration = []; createAttribute.enumeration[0] = {"value":1,"label":"Beginner"}; createAttribute.enumeration[1] = {"value":2,"label":"Intermediate"}; createAttribute.enumeration[2] = {"value":3,"label":"Expert"}; createAttribute.type = 'category'; apiInstance.createAttribute(attributeCategory, attributeName, createAttribute).then(function() { console.log('API called successfully.'); }, function(error) { console.error(error); });
<?php require_once(__DIR__ . '/vendor/autoload.php'); $config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR API KEY'); $apiInstance = new SendinBlue\Client\Api\AttributesApi( new GuzzleHttp\Client(), $config ); $attributeCategory = 'category'; $attributeName = 'levelOfExpertise'; $createAttribute = new \SendinBlue\Client\Model\CreateAttribute(); try { $apiInstance->createAttribute($attributeCategory, $attributeName, $createAttribute); } catch (Exception $e) { echo 'Exception when calling AttributesApi->createAttribute: ', $e->getMessage(), PHP_EOL; } ?>
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'] = 'YOUR API KEY' api_instance = sib_api_v3_sdk.ContactsApi(sib_api_v3_sdk.ApiClient(configuration)) attribute_category = 'category' attribute_name = 'levelOfExpertise' create_attribute = sib_api_v3_sdk.CreateAttribute() create_attribute.enumeration = [] create_attribute.enumeration.append({"value":1,"label":"Beginner"}) create_attribute.enumeration.append({"value":2,"label":"Intermediate"}) create_attribute.enumeration.append({"value":3,"label":"Expert"}) create_attribute.type = 'category' try: api_instance.create_attribute(attribute_category, attribute_name, create_attribute) except ApiException as e: print("Exception when calling ContactsApi->create_attribute: %s\n" % e)
const SibApiV3Sdk = require('sib-api-v3-typescript'); let apiInstance = new SibApiV3Sdk.ContactsApi() let apiKey = apiInstance.authentications['apiKey']; apiKey.apiKey = 'YOUR API KEY'; let attributeCategory = "category"; let attributeName = "levelOfExpertise"; let createAttribute = new SibApiV3Sdk.CreateAttribute(); createAttribute.enumeration = []; createAttribute.enumeration[0] = {"value":1,"label":"Beginner"}; createAttribute.enumeration[1] = {"value":2,"label":"Intermediate"}; createAttribute.enumeration[2] = {"value":3,"label":"Expert"}; createAttribute.type = 'category'; apiInstance.createAttribute(attributeCategory, attributeName, createAttribute).then(function() { console.log('API called successfully.'); }, function(error) { console.error(error); });
package sibApi; import sendinblue.ApiClient; import sendinblue.Configuration; import sendinblue.auth.ApiKeyAuth; import sibModel.*; import java.util.*; import java.util.List; public class Program { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); // Configure API key authorization: api-key ApiKeyAuth apiKey = (ApiKeyAuth) defaultClient.getAuthentication("api-key"); apiKey.setApiKey("YOUR API KEY"); try { ContactsApi api = new ContactsApi(); String attributeCategory = "category"; String attributeName = "levelOfExpertise"; CreateAttributeEnumeration Beginner = new CreateAttributeEnumeration(); Beginner.setLabel("Beginner"); Beginner.setValue(1); CreateAttributeEnumeration Intermediate = new CreateAttributeEnumeration(); Intermediate.setLabel("Intermediate"); Intermediate.setValue(2); CreateAttributeEnumeration Expert = new CreateAttributeEnumeration(); Expert.setLabel("Expert"); Expert.setValue(3); List<CreateAttributeEnumeration> enumerations = new ArrayList<CreateAttributeEnumeration>(); enumerations.add(Beginner); enumerations.add(Intermediate); enumerations.add(Expert); CreateAttribute createAttribute = new CreateAttribute(); createAttribute.setType(CreateAttribute.TypeEnum.CATEGORY); createAttribute.setEnumeration(enumerations); api.createAttribute(attributeCategory, attributeName, createAttribute); } catch (Exception e) { System.out.println("Exception occurred:- " + e.getMessage()); } } }
using sib_api_v3_sdk.Api; using sib_api_v3_sdk.Client; using sib_api_v3_sdk.Model; using System; using System.Diagnostics; using System.Collections.Generic; namespace Sendinblue { class Program { static void Main(string[] args) { Configuration.Default.ApiKey.Add("api-key", "YOUR API KEY"); var apiInstance = new ContactsApi(); string attributeCategory = "category"; string attributeName = "levelOfExpertise"; string value = null; CreateAttributeEnumeration Beginner = new CreateAttributeEnumeration(1, "Beginner"); CreateAttributeEnumeration Intermediate = new CreateAttributeEnumeration(2, "Intermediate"); CreateAttributeEnumeration Expert = new CreateAttributeEnumeration(3, "Expert"); List<CreateAttributeEnumeration> enumerations = new List<CreateAttributeEnumeration>(); enumerations.Add(Beginner); enumerations.Add(Intermediate); enumerations.Add(Expert); CreateAttribute.TypeEnum? type = CreateAttribute.TypeEnum.Category; try { var createAttribute = new CreateAttribute(value, enumerations, type); apiInstance.CreateAttribute(attributeCategory, attributeName, createAttribute); Console.ReadLine(); } catch (Exception e) { Debug.WriteLine(e.Message); Console.WriteLine(e.Message); Console.ReadLine(); } } } }
package main import ( "fmt" "context" sib_api_v3_sdk "./lib" ) func main() { var ctx context.Context var cli = sib_api_v3_sdk.APIClient{ cfg: sib_api_v3_sdk.NewConfiguration(), } //Configure API key authorization: api-key cli.cfg.AddDefaultHeader("api-key", "YOUR_API_KEY") sib := sib_api_v3_sdk.NewAPIClient(cli.cfg) body := CreateAttribute{ Enumeration: []CreateAttributeEnumeration{ {Value: 1, Label: "Beginner"}, {Value: 2, Label: "Intermediate"}, {Value: 3, Label: "Expert"}, }, Type_: "category", } attributeCategory := "category" attributeName := "levelOfExpertise" resp, err := sib.ContactsApi.CreateAttribute(ctx, body, attributeCategory, attributeName) if err!=nil{ fmt.Println("Error in ContactsApi.CreateAttribute",err.Error()) return } fmt.Println( "CreateAttribute response:",resp) return }
# load the gem require 'sib-api-v3-sdk' # setup authorization SibApiV3Sdk.configure do |config| # Configure API key authorization: api-key config.api_key['api-key'] = 'YOUR API KEY' end api_instance = SibApiV3Sdk::ContactsApi.new attribute_category = 'category' # String | Category of the attribute attribute_name = 'levelOfExpertise' # String | Name of the attribute create_attribute = SibApiV3Sdk::CreateAttribute.new # CreateAttribute | Values to create an attribute create_attribute = { 'enumeration'=> [{'value'=>1,'label'=>'Beginner'},{'value'=>2,'label'=>'Intermediate'},{'value'=>3,'label'=>'Expert'}], 'type'=> 'category' } begin #Create contact attribute api_instance.create_attribute(attribute_category, attribute_name, create_attribute) rescue SibApiV3Sdk::ApiError => e puts "Exception when calling ContactsApi->create_attribute: #{e}" end
Path Params
string
required

Category of the attribute

string
required

Name of the attribute

Body Params

Values to create an attribute

string

Value of the attribute. Use only if the attribute's category is 'calculated' or 'global'

boolean

Type of the attribute. Use only if the attribute's category is 'calculated' or 'global'

enumeration
array of objects

List of values and labels that the attribute can take. Use only if the attribute's category is "category". For example:
[{"value":1, "label":"male"}, {"value":2, "label":"female"}]

enumeration
multiCategoryOptions
array of strings

List of options you want to add for multiple-choice attribute. Use only if the attribute's category is "normal" and attribute's type is "multiple-choice". For example:
["USA","INDIA"]

multiCategoryOptions
string

Type of the attribute. Use only if the attribute's category is 'normal', 'category' or 'transactional'
Type user and multiple-choice is only available if the category is normal attribute
Type id is only available if the category is transactional attribute
Type category is only available if the category is category attribute

Responses
201

Attribute created

Language
Credentials
Click Try It! to start a request and see the response here! Or choose an example:
application/json