# Attributes

> An attribute represents a characteristic of a given entity, and you can use it in your rules.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

Each attribute is described by its:

- **Type**, for instance, `string` or `number`.
- **Definition**:
  - <Attribute name="Built in" type="builtin" /> attributes: They are provided by Talon.One.
  - <Attribute name="Custom" type="custom" /> attributes: They are created by you.

:::important
There is no difference in use. You can choose to use only custom attributes if you want.
:::

**Examples:**

- An online fashion retailer might add a <Attribute name="Brand" type="custom" /> attribute belonging to _cart items_
  to apply discounts on a given brand.
- A hotel-booking platform might add the <Attribute name="CheckInTime" type="custom" />
  and <Attribute name="CheckOutTime" type="custom" /> attributes
  to _customer sessions_ and trigger extra notifications depending on the season.
- An ecommerce shop might add a <Attribute name="Segment" type="custom" /> attribute to _customer profiles_ to trigger
  targeted campaigns.

## Built-in attributes

The core data model defines a small set of common attributes for many entities, such
as names for customer profiles and prices for cart items.

To learn about viewing built-in attributes in the Campaign Manager,
see [Display attributes](/docs/product/account/dev-tools/manage-attributes.md#display-attributes).

:::tip
Depending on your attribute usage, you can control the visibility of attributes in the Attribute Selector.
See [Manage attribute visibility](/docs/product/account/dev-tools/manage-attributes.md#manage-attribute-visibility).
:::

## Custom attributes

You can also create and define your own attributes to manipulate the data of your choice.

Let's imagine our online business service includes an in-house community forum. We want to offer special
promotions to active forum users.

To do this, we can [create a custom attribute](/docs/product/account/dev-tools/manage-attributes.md#create-a-custom-attribute)
called <Attribute name="ForumPosts" type="custom" /> with associated entity **customer profile**.
We can use this attribute to track the number of times the user has posted on the forum.
We can also reward the users with the help of promotional campaigns.

:::note
After the attribute is created, it is ready for use but has no value. You can set the
value of the attribute [programmatically](#set-attributes) or in the [Campaign Manager](/docs/product/account/dev-tools/manage-attributes.md#set-the-value-of-an-attribute).
:::

## Set attributes

Once you have created attributes, or once you know which built-in ones to use,
you can assign values to them programmatically with the following endpoints:

- [Update customer profile][updateCustomerProfile] for customer profile attributes.
- [Track event][Event] endpoint for event attributes.
- The [campaign settings](/docs/product/campaigns/settings/manage-campaign-custom-attributes.md) for campaign attributes.
- The [Application settings](/docs/product/applications/use-attributes.md) for Application attributes.
- [Update customer session][updateCS] for all other attributes.

For example, consider the <Attribute name="ForumPosts" type="custom" /> attribute from above.
To keep the count of forum posts synced between Talon.One and the forum, we can use
the [updateCustomerProfile][updateCustomerProfile] endpoint
every time the user makes a post to update the stats.

<Tabs defaultValue="curl"  values={[
    {label: 'curl', value: 'curl'},
    {label: 'JavaScript', value: 'JavaScript'},
    {label: 'Ruby', value: 'ruby'},
    ]}
    >

  <TabItem value="curl">

  Using the [updateCustomerProfile][updateCustomerProfile] endpoint:

```json
CURL -X PUT https://mycompany.europe-west1.talon.one/v2/customer_profiles/{sessionId} -d
'{
  "attributes": {
    "ForumPosts": someValue
  }
}'
```

  </TabItem>

  <TabItem value="JavaScript">

  Using the [JavaScript SDK](/docs/dev/sdks/overview.md):

```javascript
talon.updateCustomerProfileV2(user.id, {
  attributes: {
    ForumPosts: await user.postCount()
  }
})
```

  </TabItem>

  <TabItem value="ruby">

  Using the [Ruby SDK](/docs/dev/sdks/overview.md):

```ruby
talon.update_customer_profile_v2 user.id, {
  "attributes" => {
    "ForumPosts" => user.posts.length
  }
}
```
  </TabItem>
</Tabs>

The attribute value must match the attributes type. The following types are supported:

- `string`: Any valid JSON string of maximum 5000 characters.
- `number`: Any valid JSON number. These values are internally treated as big decimal numbers.
- `boolean`: Either `true` or `false`.
- `time`: An RFC3339 timestamp.
- `location`: See [Use geolocation](/docs/dev/tutorials/use-geolocation.md).
- `list of strings`: Comma separated list of strings of maximum 1000 characters each.
  Contains up to 1000 items.
- `list of numbers`: Comma separated list of numbers. Contains up to 1000 items.

You can also remove any attribute value by setting it to `null`.

:::important
Talon.One will return a 400 error whenever an unknown attribute is transferred in a
session. An unknown attribute doesn't appear in the Campaign Manager.
:::

## Related pages

- [Webhooks](/docs/product/account/dev-tools/manage-webhooks.md)
- [Manage attributes](/docs/product/account/dev-tools/manage-attributes.md)

[updateCS]: /integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2
[updateCustomerProfile]: /integration-api#tag/Customer-profiles/operation/updateCustomerProfileV2
[event]: /docs/dev/concepts/entities/events.md#create-an-event
