# Import customer data

> When you first integrate with Talon.One, ensure you import information about your existing customers to maximize the use of targeted campaigns immediately.

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

Customer data consists of two entities:
- [Customer profiles](/docs/dev/concepts/entities/customer-profiles.md)
- [Customer sessions](/docs/dev/concepts/entities/customer-sessions.md), which represent orders.

:::tip Overview
- You can only import **customer profiles** programmatically using the [Update customer profile][updateCustomerProfile]
  and [Update multiple customer profiles][updateCustomerProfiles]
  endpoints.
- You can only import your customers' **historical sales data** programmatically using the
  [Update customer session][updateCustomerSession] endpoint.
:::

## Prerequisites

1. You have [created an Application](/docs/product/applications/create-and-manage-applications.md)
   in Talon.One.
1. You have created an [Integration API key](/docs/product/applications/manage-api-keys.md).

## Step 1: Import customer profiles

In Talon.One, [customer profile](/docs/dev/concepts/entities/customer-profiles.md) entities
represent the data related to your customers.

This example shows how to import customer profile data using the [Update customer profile][updateCustomerProfile]
endpoint both directly and via an SDK.

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

  <TabItem value="curl">

```bash
curl --request PUT 'https://example.talon.one/v2/customer_profiles/mysessionid' \
  --header 'Authorization: ApiKey-v1 my_api_key' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "attributes": {
      "Name": "John doe",
      "Email": "john.doe@example.com",
      "SignupDate": "2012-07-09T19:22:09.1440844Z",
      "Phone": "202-555-0113"
    },
    "responseContent": [
      "customerProfile"
    ]
  }'
```

  </TabItem>

  <TabItem value="ruby">

Using the [Ruby SDK](/docs/dev/sdks/overview.md), you can use the following style of loop:

```ruby
talon = TalonOne::Integration::Client.new

User.each do |user|
  talon.update_customer_profile_v2 "user-#{user.id}", {
    :attributes => {
      "Name" => user.name,
      "Email" => user.email,
      "SignupDate" => user.created_at,
      "Phone" => user.phone_number,
    }
  }
end
```

  </TabItem>
</Tabs>

:::note
- Mapping your _customer data_ to _profile attributes_ depends on your Application.
- You can define [your own profile attributes](/docs/dev/concepts/attributes.md#custom-attributes)
  for any data you need for your targeted campaigns.
:::

## Step 2: Import past customer orders

You can import the historical sales data of your customers to use it in your
campaigns. In Talon.One, past customer orders are considered [closed sessions](/docs/dev/concepts/entities/customer-sessions.md).

Similar to importing customer profiles, you can loop through these past orders and create a
closed session for each order using the [Update customer session][updateCustomerSession] endpoint.

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

  <TabItem value="curl">

Values between angle brackets mean they come from your order management system.

```bash {7} showLineNumbers
curl --request PUT 'https://example.talon.one/v2/customer_sessions/mysessionid' \
  --header 'Authorization: ApiKey-v1 my_api_key' \
  --header 'Content-Type: application/json' \
  --data-raw '{
    "customerSession": {
      "profileId": "<somecustomerid>",
      "state": "closed",
      "total": "<ordertotal>",
      "attributes": {
        "BillingName": "<billinginfo>",
        "ShippingCost": "<shippingcost>"
      }
    },
    "responseContent": [
      "customerSession",
      "customerProfile"
    ]
  }'
```

  </TabItem>

  <TabItem value="ruby">

Using the [Ruby SDK](/docs/dev/sdks/overview.md), you can use the following style of loop:

```ruby {5}
Order.where(:state => "closed").each do |order|
  talon.update_customer_session "order-#{order.id}", {
    "profileId" => "user-#{order.user.id}",
    "total" => order.total,
    "state" => "closed",
    "attributes" => {
      "BillingName" => order.billing_details.name,
      "ShippingCost" => order.shipping_cost,
    }
  }
```

  </TabItem>
</Tabs>

:::note
- Mapping your _order history_ to _session attributes_
  depends on your Application.
- See [Attributes][attributes] for more information on custom attributes and how to
  use them.
- The `profileId` of a session should match the ID you assigned to the customer profile when you used the [Update customer profile][updateCustomerProfile] endpoint.
- The `state` of a session must be set to `closed` for Talon.One to include that
  order in the total sales calculation for the associated profile.
:::

## Related links

- [Attributes][attributes]
- [Display customer profiles][customerprofiles]
- [Managing customer sessions][customersessions]

[customersessions]: /docs/dev/concepts/entities/customer-sessions.md
[attributes]: /docs/dev/concepts/attributes.md
[updateCustomerProfile]: /integration-api#tag/Customer-profiles/operation/updateCustomerProfileV2
[updateCustomerProfiles]: /integration-api#tag/Customer-profiles/operation/updateCustomerProfilesV2
[updateCustomerSession]: /integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2
[customerprofiles]: /docs/product/applications/display-customer-profiles.md
