Add Custom Attributes to a Customer
POST https://api.chartmogul.com/v1/customers/{CUSTOMER_UUID}/attributes/custom
Adds custom attributes to a given customer.
curl -X POST "https://api.chartmogul.com/v1/customers/cus_de305d54-75b4-431b-adb2-eb6b9e546012/attributes/custom" \
-u YOUR_API_KEY: \
-H "Content-Type: application/json" \
-d '{
"custom": [
{"type": "String", "key": "channel", "value": "Facebook", "source": "integration"},
{"type": "Integer", "key": "age", "value": 8}
],
"overrides": { "custom": { "channel": true } }
}'
customer = ChartMogul::Customer.retrieve("cus_de305d54-75b4-431b-adb2-eb6b9e546012")
customer.add_custom_attributes!(
{ type: "String", key: "channel", value: "Facebook", source: "integration" },
{ type: "Integer", key: "age", value: 8 }
)
ChartMogul.CustomAttribute.add(
config,
"cus_de305d54-75b4-431b-adb2-eb6b9e546012",
{
custom: [
{
type: "String",
key: "channel",
value: "Facebook",
source: "integration",
},
{
type: "Integer",
key: "age",
value: 8,
},
],
}
);
$customer = ChartMogul\Customer::retrieve("cus_de305d54-75b4-431b-adb2-eb6b9e546012");
$custom = $customer->addCustomAttributes(
["type" => "String", "key" => "channel", "value" => "Facebook", "source" => "integration"],
["type" => "Integer", "key" => "age", "value" => 8]
);
api.AddCustomAttributesToCustomer("cus_de305d54-75b4-431b-adb2-eb6b9e546012",
[]*cm.CustomAttribute{
&cm.CustomAttribute{
Type: "String",
Key: "channel",
Value: "Facebook",
Source: "integration"},
&cm.CustomAttribute{
Type: "Integer",
Key: "CAC",
Value: 8},
}
)
chartmogul.CustomAttributes.add(
config,
uuid="cus_de305d54-75b4-431b-adb2-eb6b9e546012",
data={
"custom": [
{
"type": "String",
"key": "channel",
"value": "Facebook",
"source": "integration",
},
{
"type": "Integer",
"key": "CAC",
"value": 8
},
]
},
)
{
"custom": {
"CAC": 213,
"utmCampaign": "social media 1",
"convertedAt": "2022-09-08 00:00:00",
"pro": false,
"salesRep": "Gabi",
"channel": "Facebook",
"age": 8
},
"overrides": { "custom": { "channel": true } }
}
{
:CAC => 213,
:utmCampaign => "social media 1",
:convertedAt => "2022-09-08 00:00:00",
:pro => false,
:salesRep => "Gabi",
:channel => "Facebook",
:age => 8,
}
{
custom: {
CAC: 213,
utmCampaign: "social media 1",
convertedAt: "2022-09-08 00:00:00",
pro: false,
salesRep: "Gabi",
channel: "Facebook",
age: 8
}
}
array (
"CAC" => 213,
"utmCampaign" => "social media 1",
"convertedAt" => "2022-09-08 00:00:00",
"pro" => false,"salesRep" => "Gabi",
"channel" => "Facebook",
"age" => 8
)
(*chartmogul.CustomAttributes)(0xc04206c030)({
Custom: (map[string]interface {}) (len=2) {
(string) (len=3) "CAC": (float64) 8,
(string) (len=7) "channel": (string) (len=8) "Facebook"
}
})
<CustomAttributes{
custom={
"CAC": 8,
"channel": "Facebook"}
}>
Path parameters
customer_uuidstring required- The ChartMogul UUID of the customer.
Body parameters
customarray(object) required-
An
Arraycontaining the custom attributes to be added to the customer. Each custom attribute must have atype,key, andvalueas described below.typestring required-
The data type of the custom attribute. Can be one of
String,Integer,Decimal,Timestamp, orBoolean.Supported data types and their accepted formats.
String– Accepts alphanumeric characters. Maximum of 255 characters allowed.Integer– Accepts only numeric characters.Decimal– Accepts floating point numbers.Timestamp– In the ISO 8601 format.Boolean– Can be one ofTRUE,true,t,1,FALSE,false,f, or0.
keystring required-
The name of the custom attribute. Accepts alphanumeric characters and underscores.
valuestring required-
The value of the custom attribute. Should be of the data type as specified in
type. sourcestring optional default: "API"-
Optional parameter to specify where the custom attribute was created. Defaults to
API. Not included in the response.
overridesobject optional-
Boolean flags that set or remove overrides on custom attributes, nested by namespace, e.g.
{"custom": {"channel": true}}.trueoverrides the attribute with its value once this request is applied — an overridden value is protected, so later updates from your billing system, or API requests without an override flag, no longer change it.falseremoves an existing override; if the request carries no new value for the attribute, it reverts to the latest value from the customer’s edit history. The attribute must already exist in your account with history tracking enabled — one first added by this same request does not qualify (falseis always accepted). Namespaced and nested attribute names from your integrations work too, e.g.{"stripe": {"metadata": {"plan": true}}}, and a flagged attribute needs no value in the same request — its current value is protected as-is.
Response
In the response, custom contains all the custom attributes now on this customer, and overrides flags the currently overridden ones.