Amazon Personalize Events examples using SDK for JavaScript (v3) - Amazon SDK for JavaScript
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

The Amazon SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the Amazon SDK for JavaScript version 3 (V3).

Amazon Personalize Events examples using SDK for JavaScript (v3)

The following code examples show you how to perform actions and implement common scenarios by using the Amazon SDK for JavaScript (v3) with Amazon Personalize Events.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios and cross-service examples.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Each example includes a link to GitHub, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use PutEvents.

SDK for JavaScript (v3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

// Get service clients module and commands using ES6 syntax. import { PutEventsCommand } from "@aws-sdk/client-personalize-events"; import { personalizeEventsClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Convert your UNIX timestamp to a Date. const sentAtDate = new Date(1613443801 * 1000); // 1613443801 is a testing value. Replace it with your sentAt timestamp in UNIX format. // Set put events parameters. var putEventsParam = { eventList: [ /* required */ { eventType: "EVENT_TYPE" /* required */, sentAt: sentAtDate /* required, must be a Date with js */, eventId: "EVENT_ID" /* optional */, itemId: "ITEM_ID" /* optional */, }, ], sessionId: "SESSION_ID" /* required */, trackingId: "TRACKING_ID" /* required */, userId: "USER_ID" /* required */, }; export const run = async () => { try { const response = await personalizeEventsClient.send( new PutEventsCommand(putEventsParam), ); console.log("Success!", response); return response; // For unit tests. } catch (err) { console.log("Error", err); } }; run();
  • For API details, see PutEvents in Amazon SDK for JavaScript API Reference.

The following code example shows how to use PutItems.

SDK for JavaScript (v3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

// Get service clients module and commands using ES6 syntax. import { PutItemsCommand } from "@aws-sdk/client-personalize-events"; import { personalizeEventsClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Set the put items parameters. For string properties and values, use the \ character to escape quotes. var putItemsParam = { datasetArn: "DATASET_ARN" /* required */, items: [ /* required */ { itemId: "ITEM_ID" /* required */, properties: '{"PROPERTY1_NAME": "PROPERTY1_VALUE", "PROPERTY2_NAME": "PROPERTY2_VALUE", "PROPERTY3_NAME": "PROPERTY3_VALUE"}' /* optional */, }, ], }; 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();
  • For API details, see PutItems in Amazon SDK for JavaScript API Reference.

The following code example shows how to use PutUsers.

SDK for JavaScript (v3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

// Get service clients module and commands using ES6 syntax. import { PutUsersCommand } from "@aws-sdk/client-personalize-events"; import { personalizeEventsClient } from "./libs/personalizeClients.js"; // Or, create the client here. // const personalizeEventsClient = new PersonalizeEventsClient({ region: "REGION"}); // Set the put users parameters. For string properties and values, use the \ character to escape quotes. var putUsersParam = { datasetArn: "DATASET_ARN", users: [ { userId: "USER_ID", properties: '{"PROPERTY1_NAME": "PROPERTY1_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();
  • For API details, see PutUsers in Amazon SDK for JavaScript API Reference.