Amazon SDK for JavaScript V3 API 参考指南详细描述了 Amazon SDK for JavaScript 版本 3 (V3) 的所有API操作。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 for JavaScript (v3) SDK 的亚马逊个性化事件示例
以下代码示例向您展示了如何使用带有 Amazon Personalize Events 的 Amazon SDK for JavaScript (v3) 来执行操作和实现常见场景。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例显示了如何使用PutEvents
。
- SDK对于 JavaScript (v3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 // 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. const 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();
-
有关API详细信息,请参阅 “Amazon SDK for JavaScript API参考 PutEvents” 中的。
-
以下代码示例显示了如何使用PutItems
。
- SDK对于 JavaScript (v3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 // 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. const 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();
-
有关API详细信息,请参阅 “Amazon SDK for JavaScript API参考 PutItems” 中的。
-
以下代码示例显示了如何使用PutUsers
。
- SDK对于 JavaScript (v3)
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 Amazon 代码示例存储库
中进行设置和运行。 // 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. const 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();
-
有关API详细信息,请参阅 “Amazon SDK for JavaScript API参考 PutUsers” 中的。
-