Retrieve in-app messages for an endpoint programmatically using Amazon Pinpoint - Amazon Pinpoint

End of support notice: On October 30, 2026, AWS will end support for Amazon Pinpoint. After October 30, 2026, you will no longer be able to access the Amazon Pinpoint console or Amazon Pinpoint resources (endpoints, segments, campaigns, journeys, and analytics). For more information, see Amazon Pinpoint end of support. Note: APIs related to SMS, voice, mobile push, OTP, and phone number validate are not impacted by this change and are supported by AWS End User Messaging.

Retrieve in-app messages for an endpoint programmatically using Amazon Pinpoint

Your applications can call the GetInAppMessages API to retrieve all of the in-app messages that a given endpoint is entitled to. When you call the GetInAppMessages API, you provide the following parameters:

  • ApplicationId – The unique ID of the Amazon Pinpoint project that the in-app message campaign is associated with.

  • EndpointId – The unique ID of the endpoint that you're retrieving messages for.

When you call the API with these values, it returns a list of messages. For more information about the response produced by this operation, see GetInAppMessages Amazon Pinpoint API response JSON example.

You can use the AWS SDKs to call the GetInAppMessages operation. The following code examples include functions that retrieve in-app messages.

JavaScript

Create the client in a separate module and export it:

import { PinpointClient } from "@aws-sdk/client-pinpoint"; const REGION = "us-east-1"; const pinClient = new PinpointClient({ region: REGION }); export { pinClient };

Retrieve in-app messages for an endpoint:

// Import required AWS SDK clients and commands for Node.js import { PinpointClient, GetInAppMessagesCommand } from "@aws-sdk/client-pinpoint"; import { pinClient } from "./lib/pinClient.js"; ("use strict"); //The Amazon Pinpoint application ID. const projectId = "4c545b28d21a490cb51b0b364example"; //The ID of the endpoint to retrieve messages for. const endpointId = "c5ac671ef67ee3ad164cf7706example"; const params = { ApplicationId: projectId, EndpointId: endpointId }; const run = async () => { try { const data = await pinClient.send(new GetInAppMessagesCommand(params)); console.log(JSON.stringify(data, null, 4)); return data; } catch (err) { console.log("Error", err); } }; run();
Python
import logging import boto3 from botocore.exceptions import ClientError logger = logging.getLogger(__name__) def retrieve_inapp_messages( pinpoint_client, project_id, endpoint_id): """ Retrieves the in-app messages that a given endpoint is entitled to. :param pinpoint_client: A Boto3 Pinpoint client. :param project_id: An Amazon Pinpoint project ID. :param endpoint_id: The ID of the endpoint to retrieve messages for. :return: A JSON object that contains information about the in-app message. """ try: response = pinpoint_client.get_in_app_messages( ApplicationId=project_id, EndpointId=endpoint_id) except ClientError: logger.exception("Couldn't retrieve messages.") raise else: return response def main(): project_id = "4c545b28d21a490cb51b0b364example" endpoint_id = "c5ac671ef67ee3ad164cf7706example" inapp_response = retrieve_inapp_messages( boto3.client('pinpoint'), project_id, endpoint_id) print(inapp_response) if __name__ == '__main__': main()