

# Importing individual records into an Amazon Personalize dataset
<a name="incremental-data-updates"></a>

 After you have complete [Creating a schema and a dataset](data-prep-creating-datasets.md), you can import individual records, including item interactions, users, items, actions, or action interactions into an existing dataset. Importing data individually allows you to add small batches of records to your Amazon Personalize datasets as your catalog grows. You can import up to 10 records per individual import operation.

If you import an item, user, or action with the same ID as a record that's already in your dataset, Amazon Personalize replaces it with the new record. If you record two item interaction or action interaction events with exactly the same timestamp and identical properties, Amazon Personalize keeps only one of the events.

If you use Apache Kafka, you can use the *Kafka connector for Amazon Personalize* to stream data in real time to Amazon Personalize. For information see [Kafka Connector for Amazon Personalize ](https://github.com/aws/personalize-kafka-connector/blob/main/README.md) in the *personalize-kafka-connector* Github repository.

 If you have a large amount of historical records, we recommend that you first import data in bulk and then import data individually as necessary. See [Importing bulk data into Amazon Personalize with a dataset import job](bulk-data-import-step.md). 

**Filter updates for individual record imports**

Amazon Personalize updates any filters you created in the dataset group with your new interaction, item, and user data within 20 minutes from the last individual import. This update allows your campaigns to use your most recent data when filtering recommendations for your users. 

If you already created a recommender or deployed a custom solution version with a campaign, how new individual records influence recommendations depends on the domain use case or recipe that you use. For more information, see [Updating data in datasets after training](updating-datasets.md).

**Topics**
+ [Importing interactions individually](importing-interactions.md)
+ [Importing users individually](importing-users.md)
+ [Importing items individually](importing-items.md)
+ [Importing actions individually](importing-actions.md)

# Importing interactions individually
<a name="importing-interactions"></a>

 After you complete [Creating a schema and a dataset](data-prep-creating-datasets.md) to create an Item interactions dataset, you can individually import one or more new events into the dataset. To import interaction *[events](https://docs.aws.amazon.com/glossary/latest/reference/glos-chap.html#event)* individually, you create an *[event tracker](https://docs.aws.amazon.com/glossary/latest/reference/glos-chap.html#event-tracker)* and then import one or more events into your Item interactions dataset. You can import historical individual interaction events using the Amazon Personalize console, or import historical or real-time events using the AWS Command Line Interface (AWS CLI), or the AWS SDKs.

This section includes information about importing events with the Amazon Personalize console. We recommend using the Amazon Personalize console to import *only* historical events. For information about using the AWS CLI or the AWS SDKs to record events in real-time, see [Recording real-time events to influence recommendations](recording-events.md). 

For information about how Amazon Personalize updates filters for new records and how new records influence recommendations, see [Importing individual records into an Amazon Personalize dataset](incremental-data-updates.md). 

**Topics**
+ [Creating an event tracker (console)](#event-tracker-console)
+ [Importing events individually (console)](#importing-interactions-console)

## Creating an event tracker (console)
<a name="event-tracker-console"></a>

**Note**  
 If you've created an event tracker, you can skip to [Importing events individually (console)](#importing-interactions-console). 

Before you can import an event to an Interactions dataset, you must create an *[event tracker](https://docs.aws.amazon.com/glossary/latest/reference/glos-chap.html#event-tracker)* for the dataset group. 

**To create an event tracker (console)**

1. Open the Amazon Personalize console at [https://console.aws.amazon.com/personalize/home](https://console.aws.amazon.com/personalize/home) and sign in to your account.

1.  On the **Dataset groups** page, choose the dataset group with the Item interactions dataset that you want to import events to.

1. On the **Dashboard** for the dataset group, in **Install event ingestion SDK**, choose **Start**. 

1. On the **Configure tracker** page, in **Tracker configurations**, for **Tracker name**, provide a name for the event tracker, and choose **Next**.

1. The **Install the SDK** page shows the **Tracking ID** for the new event tracker and instructions for using AWS Amplify or AWS Lambda to stream event data.

   You can ignore this information because you're using the Amazon Personalize console to upload event data. If you want to stream event data using AWS Amplify or AWS Lambda in the future, you can view this information by choosing the event tracker on the **Event trackers** page. 

1. Choose **Finish**. You can now import events with the console (see [Importing events individually (console)](#importing-interactions-console) or record events in real time using the `PutEvents` operation (see [Recording real-time events to influence recommendations](recording-events.md)). 

## Importing events individually (console)
<a name="importing-interactions-console"></a>

 After you create an event tracker, you can import events individually into an Item interactions dataset. This procedure assumes you have already created an Item interactions dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

**To import events individually (console)**

1. Open the Amazon Personalize console at [https://console.aws.amazon.com/personalize/home](https://console.aws.amazon.com/personalize/home) and sign in to your account.

1. On the **Dataset groups** page, choose the dataset group with the Item interactions dataset that you want to import events to. 

1. In the navigation pane, choose **datasets**. 

1. On the **Datasets** page, choose the Interactions dataset. 

1. At the top right of the dataset details page, choose **Modify dataset**, and choose **Create record**. 

1. In **Create user-item interaction record(s)** page, for **Record input**, enter the event details in JSON format. The event's field names and values must match the schema that you used when you created the Item interactions dataset. Amazon Personalize provides a JSON template with field names and data types from this schema. You can import up to 10 events at a time.

1. Choose **Create record(s)**. In **Response**, the result of the import is listed and a success or failure message is displayed. 

# Importing users individually
<a name="importing-users"></a>

 After you complete [Creating a schema and a dataset](data-prep-creating-datasets.md) to create a Users dataset, you can individually import one or more new users into the dataset. Individually importing users allows you to keep your Users dataset current with small batch imports as your catalog grows. You can import up to 10 users at a time. If you have a large amount of new users, we recommend that you first import data in bulk and then import user data individually as necessary. See [Importing bulk data into Amazon Personalize with a dataset import job](bulk-data-import-step.md). 

You can use the Amazon Personalize console, the AWS Command Line Interface (AWS CLI), or AWS SDKs to import users. If you import a user with the same `userId` as a user that's already in your Users dataset, Amazon Personalize replaces the user with the new one. You can import up to 10 users at a time.

For information about how Amazon Personalize updates filters for new records and how new records influence recommendations, see [Importing individual records into an Amazon Personalize dataset](incremental-data-updates.md). 

**Topics**
+ [Importing users individually (console)](#importing-users-console)
+ [Importing users individually (AWS CLI)](#importing-users-cli)
+ [Importing users individually (AWS SDKs)](#importing-users-sdk)

## Importing users individually (console)
<a name="importing-users-console"></a>

You can import up to 10 users at a time. This procedure assumes you have already created a Users dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

**To import users individually (console)**

1. Open the Amazon Personalize console at [https://console.aws.amazon.com/personalize/home](https://console.aws.amazon.com/personalize/home) and sign in to your account.

1. On the **Dataset groups** page, choose the dataset group with the Users dataset that you want to import the user to. 

1. In the navigation pane, choose **Datasets**. 

1. On the **Datasets** page, choose the Users dataset. 

1. On the dataset details page, at the top right, choose **Modify dataset** and choose **Create record**. 

1. On the **Create user record(s)** page, for record input, enter the user details in JSON format. The user's field names and values must match the schema you used when you created the Users dataset. Amazon Personalize provides a JSON template with field names and data types from this schema. 

1. Choose **Create record(s)**. In **Response**, the result of the import is listed and a success or failure message is displayed.

## Importing users individually (AWS CLI)
<a name="importing-users-cli"></a>

Add one or more users to your Users dataset with the [PutUsers](API_UBS_PutUsers.md) operation. You can import up to 10 users with a single `PutUsers` call. This section assumes that you have already created an Users dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

Use the following `put-users` command to add one or more users with the AWS CLI. Replace `dataset arn` with the Amazon Resource Name (ARN) of your dataset and `user Id` with the ID of the user. If an user with the same `userId` is already in your Users dataset, Amazon Personalize replaces it with the new one.

For `properties`, for each field in your Users dataset, replace the `propertyName` with the field name from your schema in camel case. For example, GENDER would be `gender` and MEMBERSHIP\$1TYPE would be `membershipType`. Replace `user data` with the data for the user. For categorical string data, to include multiple categories for a single property, separate each category with a pipe (`|`). For example `\"Premium Class|Legacy Member\"`.

```
aws personalize-events put-users \
  --dataset-arn dataset arn \
  --users '[{
      "userId": "user Id", 
      "properties": "{\"propertyName\": "\user data\"}" 
    }, 
    {
      "userId": "user Id", 
      "properties": "{\"propertyName\": "\user data\"}" 
    }]'
```

## Importing users individually (AWS SDKs)
<a name="importing-users-sdk"></a>

Add one or more users to your Users dataset with the [PutUsers](API_UBS_PutUsers.md) operation. If a user with the same `userId` is already in your Users dataset, Amazon Personalize replaces it with the new one. You can import up to 10 users with a single `PutUsers` call. This section assumes that you have already created a Users dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

 The following code shows how to add one or more users to your Users dataset. For each property name parameter, pass the field name from your schema in camel case. For example, GENDER would be `gender` and MEMBERSHIP\$1TYPE would be `membershipType`. For each property value parameter, pass the data for the user. 

For categorical string data, to include multiple categories for a single property separate each category with a pipe (`|`). For example `"Premium class|Legacy Member"`.

------
#### [ SDK for Python (Boto3) ]

```
import boto3

personalize_events = boto3.client(service_name='personalize-events')

personalize_events.put_users(
    datasetArn = 'dataset arn',
    users = [{
      'userId': 'user ID',
      'properties': "{\"propertyName\": \"user data\"}"   
      },
      {
      'userId': 'user ID',
      'properties': "{\"propertyName\": \"user data\"}"   
      }]
)
```

------
#### [ SDK for Java 2.x ]

```
public static int putUsers(PersonalizeEventsClient personalizeEventsClient,
                         String datasetArn,
                         String user1Id,
                         String user1PropertyName,
                         String user1PropertyValue,
                         String user2Id,
                         String user2PropertyName,
                         String user2PropertyValue) {

    int responseCode = 0;
    ArrayList<User> users = new ArrayList<>();

    try {
        User user1 = User.builder()
          .userId(user1Id)
          .properties(String.format("{\"%1$s\": \"%2$s\"}", user1PropertyName, user1PropertyValue))
          .build();

        users.add(user1);

        User user2 = User.builder()
          .userId(user2Id)
          .properties(String.format("{\"%1$s\": \"%2$s\"}", user2PropertyName, user2PropertyValue))
          .build();

        users.add(user2);

        PutUsersRequest putUsersRequest = PutUsersRequest.builder()
          .datasetArn(datasetArn)
          .build();

        responseCode = personalizeEventsClient.putUsers(putUsersRequest).sdkHttpResponse().statusCode();
        System.out.println("Response code: " + responseCode);
        return responseCode;

    } catch (PersonalizeEventsException e) {
        System.out.println(e.awsErrorDetails().errorMessage());
    }
    return responseCode;
}
```

------
#### [ SDK for JavaScript v3 ]

```
import {
  PutUsersCommand,
  PersonalizeEventsClient,
} from "@aws-sdk/client-personalize-events";

const personalizeEventsClient = new PersonalizeEventsClient({
  region: "REGION",
});

// set the put users parameters
var putUsersParam = {
  datasetArn:
    "DATASET ARN",
  users: [
    {
      userId: "userId",
      properties: '{"column1Name": "value", "column2Name": "value"}',
    },
    {
      userId: "userId",
      properties: '{"column1Name": "value", "column2Name": "value"}',
    },
  ],
};
export const run = async () => {
  try {
    const response = await personalizeEventsClient.send(
      new PutUsersCommand(putUsersParam)
    );
    console.log("Success!", response);
    return response; // For unit tests.
  } catch (err) {
    console.log("Error", err);
  }
};
run();
```

------

# Importing items individually
<a name="importing-items"></a>

After you complete [Creating a schema and a dataset](data-prep-creating-datasets.md) to create an Items dataset, you can individually import one or more new items into the dataset. Individually importing items allows you to keep your Items dataset current with small batch imports as your catalog grows. You can import up to 10 items at a time. If you have a large amount of new items, we recommend that you first import data in bulk and then import item data individually as necessary. See [Importing bulk data into Amazon Personalize with a dataset import job](bulk-data-import-step.md).

You can use the Amazon Personalize console, the AWS Command Line Interface (AWS CLI), or AWS SDKs to import items. If you import an item with the same `itemId` as an item that's already in your Items dataset, Amazon Personalize replaces it with the new item.

 For information about how Amazon Personalize updates filters for new records and how new records influence recommendations, see [Importing individual records into an Amazon Personalize dataset](incremental-data-updates.md). 

**Topics**
+ [Importing items individually (console)](#importing-items-console)
+ [Importing items individually (AWS CLI)](#importing-items-cli)
+ [Importing items individually (AWS SDKs)](#importing-items-cli-sdk)

## Importing items individually (console)
<a name="importing-items-console"></a>

You can import up to 10 items to an Items dataset at a time. This procedure assumes that you have already created an Items dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

**To import items individually (console)**

1. Open the Amazon Personalize console at [https://console.aws.amazon.com/personalize/home](https://console.aws.amazon.com/personalize/home) and sign in to your account.

1. On the **Dataset groups** page, choose the dataset group with the Items dataset that you want to import the items to. 

1. In the navigation pane, choose **Datasets**. 

1. On the **Datasets** page, choose the Items dataset. 

1. At the top right of the dataset details page, choose **Modify dataset**, and then choose **Create record**. 

1. In **Create item record(s)** page, for **Record input**, enter the item details in JSON format. The item's field names and values must match the schema you used when you created the Items dataset. Amazon Personalize provides a JSON template with field names and data types from this schema.

1. Choose **Create record(s)**. In **Response**, the result of the import is listed and a success or failure message is displayed.

## Importing items individually (AWS CLI)
<a name="importing-items-cli"></a>

Add one or more items to your Items dataset using the [PutItems](API_UBS_PutItems.md) operation. You can import up to 10 items with a single `PutItems` call. This section assumes that you have already created an Items dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

Use the following `put-items` command to add one or more items with the AWS CLI. Replace `dataset arn` with the Amazon Resource Name (ARN) of your dataset and `item Id` with the ID of the item. If an item with the same `itemId` is already in your Items dataset, Amazon Personalize replaces it with the new one.

For `properties`, for each field in your Items dataset, replace the `propertyName` with the field name from your schema in camel case. For example, GENRES would be `genres` and CREATION\$1TIMESTAMP would be creationTimestamp. Replace `item data` with the data for the item. `CREATION_TIMESTAMP` data must be in [Unix epoch time format](interactions-datasets.md#timestamp-data) and in seconds. For categorical string data, to include multiple categories for a single property, separate each category with a pipe (`|`). For example `\"Horror|Action\"`.

```
aws personalize-events put-items \
  --dataset-arn dataset arn \
  --items '[{
      "itemId": "item Id", 
      "properties": "{\"propertyName\": "\item data\"}" 
    }, 
    {
      "itemId": "item Id", 
      "properties": "{\"propertyName\": "\item data\"}" 
    }]'
```

## Importing items individually (AWS SDKs)
<a name="importing-items-cli-sdk"></a>

Add one or more items to your Items dataset using the [PutItems](API_UBS_PutItems.md) operation. You can import up to 10 items with a single `PutItems` call. If an item with the same `itemId` is already in your Items dataset, Amazon Personalize replaces it with the new one. This section assumes that you have already created an Items dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

 The following code shows how to add one or more items to your Items dataset. For each property name parameter, pass the field name from your schema in camel case. For example, GENRES would be `genres` and CREATION\$1TIMESTAMP would be `creationTimestamp`. For each property value parameter, pass the data for the item. `CREATION_TIMESTAMP` data must be in [Unix epoch time format](interactions-datasets.md#timestamp-data) and in seconds. 

For categorical string data, to include multiple categories for a single property, separate each category with a pipe (`|`). For example `"Horror|Action"`.

------
#### [ SDK for Python (Boto3) ]

```
import boto3

personalize_events = boto3.client(service_name='personalize-events')

personalize_events.put_items(
    datasetArn = 'dataset arn',
    items = [{
      'itemId': 'item ID',
      'properties': "{\"propertyName\": \"item data\"}"   
      },
      {
      'itemId': 'item ID',
      'properties': "{\"propertyName\": \"item data\"}"   
      }]
)
```

------
#### [ SDK for Java 2.x ]

```
public static int putItems(PersonalizeEventsClient personalizeEventsClient,
                           String datasetArn,
                           String item1Id,
                           String item1PropertyName,
                           String item1PropertyValue,
                           String item2Id,
                           String item2PropertyName,
                           String item2PropertyValue) {

    int responseCode = 0;
    ArrayList<Item> items = new ArrayList<>();

    try {
        Item item1 = Item.builder()
                .itemId(item1Id)
                .properties(String.format("{\"%1$s\": \"%2$s\"}",
                        item1PropertyName, item1PropertyValue))
                .build();

        items.add(item1);

        Item item2 = Item.builder()
                .itemId(item2Id)
                .properties(String.format("{\"%1$s\": \"%2$s\"}",
                        item2PropertyName, item2PropertyValue))
                .build();

        items.add(item2);

        PutItemsRequest putItemsRequest = PutItemsRequest.builder()
                .datasetArn(datasetArn)
                .items(items)
                .build();

        responseCode = personalizeEventsClient.putItems(putItemsRequest).sdkHttpResponse().statusCode();
        System.out.println("Response code: " + responseCode);
        return responseCode;

    } catch (PersonalizeEventsException e) {
        System.out.println(e.awsErrorDetails().errorMessage());
    }
    return responseCode;
    }
```

------
#### [ SDK for JavaScript v3 ]

```
import {
  PutItemsCommand,
  PersonalizeEventsClient,
} from "@aws-sdk/client-personalize-events";

const personalizeEventsClient = new PersonalizeEventsClient({
  region: "REGION",
});

// set the put items parameters
var putItemsParam = {
  datasetArn:
    "DATASET ARN",
  items: [
    {
      itemId: "itemId", 
      properties: '{"column1Name": "value", "column2Name": "value"}',
    },
    {
      itemId: "itemId",
      properties: '{"column1Name": "value", "column2Name": "value"}',
    },
  ],
};
export const run = async () => {
  try {
    const response = await personalizeEventsClient.send(
      new PutItemsCommand(putItemsParam)
    );
    console.log("Success!", response);
    return response; // For unit tests.
  } catch (err) {
    console.log("Error", err);
  }
};
run();
```

------

# Importing actions individually
<a name="importing-actions"></a>

After you complete [Creating a schema and a dataset](data-prep-creating-datasets.md) to create an [Actions dataset](actions-datasets.md), you can individually import one or more new actions into the dataset. When you individually import actions, you keep your Actions dataset current with small batch imports as your catalog grows. You can import up to 10 actions at a time. If you have a large number of new actions, we recommend that you first import data in bulk and then import action data individually as necessary. See [Importing bulk data into Amazon Personalize with a dataset import job](bulk-data-import-step.md).

You can use the Amazon Personalize console, the AWS Command Line Interface (AWS CLI), or AWS SDKs to import actions. If you import an action with the same `actionId` as an action that's already in your Actions dataset, Amazon Personalize replaces it with the new action.

For information about how new records influence recommendations, see [Updating data in datasets after training](updating-datasets.md). 

**Topics**
+ [Importing actions individually (console)](#importing-actions-console)
+ [Importing actions individually (AWS CLI)](#importing-actions-cli)
+ [Importing actions individually (AWS SDKs)](#importing-actions-cli-sdk)

## Importing actions individually (console)
<a name="importing-actions-console"></a>

You can import up to 10 actions into an Actions dataset at a time. This section assumes that you have already created an Actions dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

**To import actions individually (console)**

1. Open the Amazon Personalize console at [https://console.aws.amazon.com/personalize/home](https://console.aws.amazon.com/personalize/home) and sign in to your account.

1. On the **Dataset groups** page, choose the dataset group with the Actions dataset that you want to add to.

1. In the navigation pane, choose **Datasets**. 

1. On the **Datasets** page, choose the Actions dataset. 

1. At the top right of the dataset details page, choose **Modify dataset**, and then choose **Create record**. 

1. In **Create action record(s)** page, for **Record input**, enter the action details in JSON format. The action's field names and values must match the schema you used when you created the Actions dataset. Amazon Personalize provides a JSON template with field names and data types from this schema.

1. Choose **Create record(s)**. In **Response**, the result of the import is listed and a success or failure message is displayed.

## Importing actions individually (AWS CLI)
<a name="importing-actions-cli"></a>

Add one or more actions to your Actions dataset using the `PutActions` API operation. You can import up to 10 actions at once. This section assumes that you have already created an Actions dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

Use the following `put-actions` command to add one or more actions with the AWS CLI. Replace `dataset arn` with the Amazon Resource Name (ARN) of your dataset and `actionId` with the ID of the action. If an action with the same `actionId` is already in your Actions dataset, Amazon Personalize replaces it with the new one.

For `properties`, for each field in your Actions dataset, replace the `propertyName` with the field name from your schema in camel case. For example, ACTION\$1EXPIRATION\$1TIMESTAMP would be `actionExpirationTimestamp` and CREATION\$1TIMESTAMP would be creationTimestamp. Replace `property data` with the data for the property.

```
aws personalize-events put-actions \
  --dataset-arn dataset arn \
  --actions '[{
      "actionId": "actionId", 
      "properties": "{\"propertyName\": "\property data\"}" 
    }, 
    {
      "actionId": "actionId", 
      "properties": "{\"propertyName\": "\property data\"}" 
    }]'
```

## Importing actions individually (AWS SDKs)
<a name="importing-actions-cli-sdk"></a>

Add one or more actions to your Actions dataset using the PutActions operation. You can import up to 10 actions with a single `PutActions` call. If an action with the same `actionId` is already in your Actions dataset, Amazon Personalize replaces it with the new one. This section assumes that you have already created an Actions dataset. For information about creating datasets, see [Creating a schema and a dataset](data-prep-creating-datasets.md).

 The following code shows how to add one or more actions to your Actions dataset. For each action, specify the `actionId`. If an action with the same `actionId` is already in your Actions dataset, Amazon Personalize replaces it with the new one. For `properties`, for each additional field in your Actions dataset, replace the `propertyName` with the field name from your schema in camel case. For example, ACTION\$1EXPIRATION\$1TIMESTAMP would be `actionExpirationTimestamp` and CREATION\$1TIMESTAMP would be creationTimestamp. Replace `property data` with the data for the property. 

```
import boto3

personalize_events = boto3.client(service_name='personalize-events')

personalize_events.put_actions(
    datasetArn = 'dataset arn',
    actions = [{
      'actionId': 'actionId',
      'properties': "{\"propertyName\": \"property value\"}"   
      },
      {
      'actionId': 'actionId',
      'properties': "{\"propertyName\": \"property value\"}"   
      }]
)
```