GetRecommendationsCommand

Returns a list of recommended items. For campaigns, the campaign's Amazon Resource Name (ARN) is required and the required user and item input depends on the recipe type used to create the solution backing the campaign as follows:

  • USER_PERSONALIZATION - userId required, itemId not used

  • RELATED_ITEMS - itemId required, userId not used

Campaigns that are backed by a solution created using a recipe of type PERSONALIZED_RANKING use the API.

For recommenders, the recommender's ARN is required and the required item and user input depends on the use case (domain-based recipe) backing the recommender. For information on use case requirements see Choosing recommender use cases .

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { PersonalizeRuntimeClient, GetRecommendationsCommand } from "@aws-sdk/client-personalize-runtime"; // ES Modules import
// const { PersonalizeRuntimeClient, GetRecommendationsCommand } = require("@aws-sdk/client-personalize-runtime"); // CommonJS import
const client = new PersonalizeRuntimeClient(config);
const input = { // GetRecommendationsRequest
  campaignArn: "STRING_VALUE",
  itemId: "STRING_VALUE",
  userId: "STRING_VALUE",
  numResults: Number("int"),
  context: { // Context
    "<keys>": "STRING_VALUE",
  },
  filterArn: "STRING_VALUE",
  filterValues: { // FilterValues
    "<keys>": "STRING_VALUE",
  },
  recommenderArn: "STRING_VALUE",
  promotions: [ // PromotionList
    { // Promotion
      name: "STRING_VALUE",
      percentPromotedItems: Number("int"),
      filterArn: "STRING_VALUE",
      filterValues: {
        "<keys>": "STRING_VALUE",
      },
    },
  ],
  metadataColumns: { // MetadataColumns
    "<keys>": [ // ColumnNamesList
      "STRING_VALUE",
    ],
  },
};
const command = new GetRecommendationsCommand(input);
const response = await client.send(command);
// { // GetRecommendationsResponse
//   itemList: [ // ItemList
//     { // PredictedItem
//       itemId: "STRING_VALUE",
//       score: Number("double"),
//       promotionName: "STRING_VALUE",
//       metadata: { // Metadata
//         "<keys>": "STRING_VALUE",
//       },
//       reason: [ // ReasonList
//         "STRING_VALUE",
//       ],
//     },
//   ],
//   recommendationId: "STRING_VALUE",
// };

GetRecommendationsCommand Input

See GetRecommendationsCommandInput for more details

Parameter
Type
Description
campaignArn
string | undefined

The Amazon Resource Name (ARN) of the campaign to use for getting recommendations.

context
Record<string, string> | undefined

The contextual metadata to use when getting recommendations. Contextual metadata includes any interaction information that might be relevant when getting a user's recommendations, such as the user's current location or device type.

filterArn
string | undefined

The ARN of the filter to apply to the returned recommendations. For more information, see Filtering Recommendations .

When using this parameter, be sure the filter resource is ACTIVE.

filterValues
Record<string, string> | undefined

The values to use when filtering recommendations. For each placeholder parameter in your filter expression, provide the parameter name (in matching case) as a key and the filter value(s) as the corresponding value. Separate multiple values for one parameter with a comma.

For filter expressions that use an INCLUDE element to include items, you must provide values for all parameters that are defined in the expression. For filters with expressions that use an EXCLUDE element to exclude items, you can omit the filter-values.In this case, Amazon Personalize doesn't use that portion of the expression to filter recommendations.

itemId
string | undefined

The item ID to provide recommendations for.

Required for RELATED_ITEMS recipe type.

metadataColumns
Record<string, string[]> | undefined

If you enabled metadata in recommendations when you created or updated the campaign or recommender, specify the metadata columns from your Items dataset to include in item recommendations. The map key is ITEMS and the value is a list of column names from your Items dataset. The maximum number of columns you can provide is 10.

For information about enabling metadata for a campaign, see Enabling metadata in recommendations for a campaign . For information about enabling metadata for a recommender, see Enabling metadata in recommendations for a recommender .

numResults
number | undefined

The number of results to return. The default is 25. If you are including metadata in recommendations, the maximum is 50. Otherwise, the maximum is 500.

promotions
Promotion[] | undefined

The promotions to apply to the recommendation request. A promotion defines additional business rules that apply to a configurable subset of recommended items.

recommenderArn
string | undefined

The Amazon Resource Name (ARN) of the recommender to use to get recommendations. Provide a recommender ARN if you created a Domain dataset group with a recommender for a domain use case.

userId
string | undefined

The user ID to provide recommendations for.

Required for USER_PERSONALIZATION recipe type.

GetRecommendationsCommand Output

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
itemList
PredictedItem[] | undefined

A list of recommendations sorted in descending order by prediction score. There can be a maximum of 500 items in the list.

recommendationId
string | undefined

The ID of the recommendation.

Throws

Name
Fault
Details
InvalidInputException
client

Provide a valid value for the field or parameter.

ResourceNotFoundException
client

The specified resource does not exist.

PersonalizeRuntimeServiceException
Base exception class for all service exceptions from PersonalizeRuntime service.