Skip to content

get_action_recommendations

get_action_recommendations(
    *,
    config_overrides: Optional[PersonalizeRuntimeClientConfig] = None,
    campaign_arn: Optional[Arn] = None,
    user_id: Optional[UserID] = None,
    num_results: Optional[NumResults] = None,
    filter_arn: Optional[Arn] = None,
    filter_values: Optional[FilterValues] = None,
) -> GetActionRecommendationsResponse

Returns a list of recommended actions in sorted in descending order by prediction score. Use the GetActionRecommendations API if you have a custom campaign that deploys a solution version trained with a PERSONALIZED_ACTIONS recipe.

For more information about PERSONALIZED_ACTIONS recipes, see PERSONALIZED_ACTIONS recipes. For more information about getting action recommendations, see Getting action recommendations.

Parameters:

  • campaign_arn (Optional[Arn], default: None ) –

    The Amazon Resource Name (ARN) of the campaign to use for getting action recommendations. This campaign must deploy a solution version trained with a PERSONALIZED_ACTIONS recipe.

  • user_id (Optional[UserID], default: None ) –

    The user ID of the user to provide action recommendations for.

  • num_results (Optional[NumResults], default: None ) –

    The number of results to return. The default is 5. The maximum is 100.

  • filter_arn (Optional[Arn], default: None ) –

    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.

  • filter_values (Optional[FilterValues], default: None ) –

    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 actions, you must provide values for all parameters that are defined in the expression. For filters with expressions that use an EXCLUDE element to exclude actions, you can omit the filter-values. In this case, Amazon Personalize doesn't use that portion of the expression to filter recommendations.

    For more information, see Filtering recommendations and user segments.

Raises:

Source code in docs_src/capo_personalize_runtime/_services/personalize_runtime.py
def get_action_recommendations(
    self,
    *,
    config_overrides: Optional[PersonalizeRuntimeClientConfig] = None,
    campaign_arn: Optional["capo_personalize_runtime.types.arn.Arn"] = None,
    user_id: Optional["capo_personalize_runtime.types.user_id.UserID"] = None,
    num_results: Optional[
        "capo_personalize_runtime.types.num_results.NumResults"
    ] = None,
    filter_arn: Optional["capo_personalize_runtime.types.arn.Arn"] = None,
    filter_values: Optional[
        "capo_personalize_runtime.types.filter_values.FilterValues"
    ] = None,
) -> "capo_personalize_runtime.types.get_action_recommendations_response.GetActionRecommendationsResponse":
    """<p>Returns a list of recommended actions in sorted in descending order by prediction score. Use the <code>GetActionRecommendations</code> API if you have a custom campaign that deploys a solution version trained with a PERSONALIZED_ACTIONS recipe. </p> <p>For more information about PERSONALIZED_ACTIONS recipes, see <a href="https://docs.aws.amazon.com/personalize/latest/dg/nexts-best-action-recipes.html">PERSONALIZED_ACTIONS recipes</a>. For more information about getting action recommendations, see <a href="https://docs.aws.amazon.com/personalize/latest/dg/get-action-recommendations.html">Getting action recommendations</a>.</p>

    Args:
        campaign_arn: <p>The Amazon Resource Name (ARN) of the campaign to use for getting action recommendations. This campaign must deploy a solution version trained with a PERSONALIZED_ACTIONS recipe.</p>
        user_id: <p>The user ID of the user to provide action recommendations for.</p>
        num_results: <p>The number of results to return. The default is 5. The maximum is 100.</p>
        filter_arn: <p>The ARN of the filter to apply to the returned recommendations. For more information, see <a href="https://docs.aws.amazon.com/personalize/latest/dg/filter.html">Filtering Recommendations</a>.</p> <p>When using this parameter, be sure the filter resource is <code>ACTIVE</code>.</p>
        filter_values: <p>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. </p> <p>For filter expressions that use an <code>INCLUDE</code> element to include actions, you must provide values for all parameters that are defined in the expression. For filters with expressions that use an <code>EXCLUDE</code> element to exclude actions, you can omit the <code>filter-values</code>. In this case, Amazon Personalize doesn't use that portion of the expression to filter recommendations.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/personalize/latest/dg/filter.html">Filtering recommendations and user segments</a>.</p>

    Raises:
        capo_personalize_runtime.errors.invalid_input_exception.InvalidInputException: <p>Provide a valid value for the field or parameter.</p>
        capo_personalize_runtime.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource does not exist.</p>
        capo_personalize_runtime.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_personalize_runtime.types.get_action_recommendations_request.GetActionRecommendationsRequest]",
    ) -> OperationResponse[
        "capo_personalize_runtime.types.get_action_recommendations_response.GetActionRecommendationsResponse"
    ]:
        import capo_personalize_runtime._operations.amazon_personalize_runtime.get_action_recommendations

        output, http_response = (
            capo_personalize_runtime._operations.amazon_personalize_runtime.get_action_recommendations.get_action_recommendations(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_personalize_runtime.types.get_action_recommendations_request.GetActionRecommendationsRequest",
    ) -> dict[str, Any]:
        import capo_personalize_runtime.types.get_action_recommendations_request

        return capo_personalize_runtime.types.get_action_recommendations_request.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("GetActionRecommendations", redact_input=_redact_input),
    )
    input_: capo_personalize_runtime.types.get_action_recommendations_request.GetActionRecommendationsRequest = {}
    if campaign_arn is not None:
        input_["campaign_arn"] = campaign_arn
    if user_id is not None:
        input_["user_id"] = user_id
    if num_results is not None:
        input_["num_results"] = num_results
    if filter_arn is not None:
        input_["filter_arn"] = filter_arn
    if filter_values is not None:
        input_["filter_values"] = filter_values

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output