Add Custom Attributes to Customers by Email
POST https://api.chartmogul.com/v1/customers/attributes/custom
Adds custom attributes to customers that have the specified email address.
curl -X POST "https://api.chartmogul.com/v1/customers/attributes/custom" \
-u YOUR_API_KEY: \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"custom": [
{"type": "String", "key": "channel", "value": "Facebook", "source": "integration"},
{"type": "Integer", "key": "age", "value": 8}
],
"overrides": { "custom": { "channel": true } }
}'
customers = ChartMogul::Customer.search("[email protected]")
customers.each { |c|
c.add_custom_attributes!(
{ type: "String", key: "channel", value: "Facebook", source: "integration" },
{ type: "Integer", key: "age", value: 8 }
)
}
ChartMogul.CustomAttribute.add(config, {
email: "[email protected]",
custom: [
{
type: "String",
key: "channel",
value: "Facebook",
source: "integration",
},
{
type: "Integer",
key: "age",
value: 8,
},
],
});
$customers = ChartMogul\Customer::search("[email protected]");
foreach ($customers->entries as $customer) {
$customer->addCustomAttributes(
["type" => "String", "key" => "channel", "value" => "Facebook", "source" => "integration"],
["type" => "Integer", "key" => "age", "value" => 8]
);
}
api.AddCustomAttributesWithEmail("[email protected]",
[]*cm.CustomAttribute{
&cm.CustomAttribute{
Type: "String",
Key: "channel",
Value: "Facebook",
Source: "integration"},
&cm.CustomAttribute{
Type: "Integer",
Key: "CAC",
Value: 8},
}
)
chartmogul.CustomAttributes.add(
config,
data={
"email": "[email protected]",
"custom": [
{
"type": "String",
"key": "channel",
"value": "Facebook",
"source": "integration",
},
{
"type": "Integer",
"key": "CAC",
"value": 8,
},
],
},
)
{
"entries": [
{
"id": 25647,
"uuid": "cus_de305d54-75b4-431b-adb2-eb6b9e546012",
"external_id": "cus_0001",
"email": "[email protected]",
"name": "Smith Company",
"mrr": 3000,
"arr": 36000,
"status": "Active",
"customer-since": "2022-06-09T13:16:00-04:00",
"billing-system-url": "https://dashboard.stripe.com/customers/cus_4Z2ZpyJFuQ0XMb",
"chartmogul-url": "https://app.chartmogul.com/#customers/25647-Smith_Company",
"billing-system-type": "Stripe",
"currency": "USD",
"currency-sign": "$",
"attributes": {
"tags": ["important", "Prio1"],
"stripe": {
"coupon": true
},
"custom": {
"channel": "Facebook",
"age": 8
}
},
"overrides": {
"attributes": { "custom": { "channel": true } }
}
}
]
}
#<ChartMogul::Customer:0x007fc7e1ca7028
@id=25647,
@uuid="cus_de305d54-75b4-431b-adb2-eb6b9e546012",
@external_id="cus_0001",
@name="Smith Company",
@email="[email protected]",
@status="Active",
@customer_since=2022-06-09 13:16:00 -04:00,
@attributes={
:tags=>["important", "Prio1"],
:stripe=>{
:coupon=> true
},
:custom=>{
:channel=> "Facebook",
:age=> 8
}
},
@mrr=3000,
@arr=36000,
@billing_system_url="https://dashboard.stripe.com/customers/cus_4Z2ZpyJFuQ0XMb",
@chartmogul_url="https://app.chartmogul.com/#customers/25647-Smith_Company",
@billing_system_type="Stripe",
@currency="USD",
@currency_sign="$"
>
{
entries: [
{
id: 25647,
uuid: "cus_de305d54-75b4-431b-adb2-eb6b9e546012",
external_id: "cus_0001",
email: "[email protected]",
name: "Smith Company",
mrr: 3000,
arr: 36000,
status: "Active",
"customer-since": "2022-06-09T13:16:00-04:00",
"billing-system-url": "https://dashboard.stripe.com/customers/cus_4Z2ZpyJFuQ0XMb",
"chartmogul-url": "https://app.chartmogul.com/#customers/25647-Smith_Company",
"billing-system-type": "Stripe",
currency: "USD",
"currency-sign": "$",
attributes: {
tags: ["important", "Prio1"],
stripe: {
coupon: true
},
custom: {
channel: "Facebook",
age: 8
}
}
}
]
}
array (
"channel" => "Facebook",
"age" => 8
)
(*chartmogul.Customers)(0xc042062e70)({
Entries: ([]*chartmogul.Customer) (len=11) {
(*chartmogul.Customer)(0xc0421ca160)({
ID: (uint32) 25647,
DataSourceUUID: (string) "",
UUID: (string) (len=40) "cus_de305d54-75b4-431b-adb2-eb6b9e546012",
ExternalID: (string) (len=8) "cus_0001",
Name: (string) (len=10) "Adam Smith",
Email: (string) (len=16) "[email protected]",
Status: (string) (len=6) "Active",
CustomerSince: (string) (len=25) "2022-06-09T13:16:00-04:00",
Attributes: (*chartmogul.Attributes)(0xc04219e240)({
Tags: ([]string) (len=2) {
(string) (len=9) "important",
(string) (len=5) "Prio1"
},
Stripe: (*chartmogul.Stripe)(0xc04219a4a0)({
UID: (uint64) 0,
Coupon: (bool) true
}),
Clearbit: (*chartmogul.Clearbit)(0xc0421d8000)({
}),
Custom: (map[string]interface {}) (len=2) {
(string) (len=7) "channel": (string) (len=8) "Facebook",
(string) (len=3) "age": (float64) 8,
}
}),
Address: (*chartmogul.Address)(<nil>),
Mrr: (float64) 3000,
Arr: (float64) 36000,
BillingSystemURL: (string) (len=57) "https://dashboard.stripe.com/customers/cus_4Z2ZpyJFuQ0XMb",
ChartmogulURL: (string) (len=57) "https://app.chartmogul.com/#customers/25647-Smith_Company",
BillingSystemType: (string) (len=6) "Stripe",
Currency: (string) (len=3) "USD",
CurrencySign: (string) (len=1) "$",
Company: (string) "",
Country: (string) "",
State: (string) "",
City: (string) "",
LeadCreatedAt: (string) "",
FreeTrialStartedAt: (string) "",
Errors: (chartmogul.Errors) chartmogul: map[]
})
},
Page: (uint32) 0,
PerPage: (uint32) 0,
HasMore: (bool) false,
CurrentPage: (int32) 0,
TotalPages: (int32) 0
})
Customers(entries=[
<Customer{
arr=36000,
attributes=<Attributes{
custom={
"channel": "Facebook",
"age": 8, },
stripe=<Stripe{
"coupon": True,
}>,
tags=["important",
"Prio1"]}>,
billing_system_type: "Stripe",
billing_system_url="https://dashboard.stripe.com/customers/cus_4Z2ZpyJFuQ0XMb",
chartmogul_url: "https://app.chartmogul.com/#customers/25647-Smith_Company",
currency="USD",
currency_sing="$",
customer_since=datetime.datetime(2022, 6, 9, 13, 16),
email="[email protected]",
external_id="cus_0001",
id=25647,
mrr=3000,
name="Smith Company",
status="Active",
uuid="cus_de305d54-75b4-431b-adb2-eb6b9e546012"
}>
])
Body parameters
emailstring required-
The email address of the customers to whom custom attributes must be added.
with_associated_emailsboolean optional default: false-
When set to
true, include not only customers that have the specified email on the customer record itself, but also customers that have any associated contact with the specified email address. If omitted or set tofalse, only customers whose email matches the query email are returned. customarray(object) required-
An
Arraycontaining the custom attributes to be added to the customers. 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 on every matched customer, 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, entries contains an array of JSON objects with the following data:
id- The internal ChartMogul ID of the customer object with specified email.
uuid- The UUID of the customer object generated by ChartMogul.
external_id- The unique external identifier for this customer, if any.
name- The name of this customer.
email- This customer's email address.
status- The status of this customer. One of
ActiveorCancelled, depending on whether the customer has any active subscriptions or not. customer-since- An RFC3339 formatted datetime attribute indicating when the customer first started paying for a subscription.
attributes- A JSON object representing this customer's attributes containing the following data:
tags- An Array of all the tags now on this customer.
stripe- A JSON object representing any metadata on this customer object in your Stripe account.
custom- A JSON object representing custom attributes that you have added to this customer.
overrides- An object flagging the customer’s currently overridden fields with
true, custom attributes nested underattributes, e.g.{"attributes": {"custom": {"channel": true}}}.