Use GetSegments with an AWS SDK - 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.

Use GetSegments with an AWS SDK

The following code examples show how to use GetSegments.

Java
SDK for Java 2.x
Note

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

List segments.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.pinpoint.PinpointClient; import software.amazon.awssdk.services.pinpoint.model.GetSegmentsRequest; import software.amazon.awssdk.services.pinpoint.model.GetSegmentsResponse; import software.amazon.awssdk.services.pinpoint.model.PinpointException; import software.amazon.awssdk.services.pinpoint.model.SegmentResponse; import java.util.List; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class ListSegments { public static void main(String[] args) { final String usage = """ Usage: <appId> Where: appId - The ID of the application that contains a segment. """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String appId = args[0]; PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); listSegs(pinpoint, appId); pinpoint.close(); } public static void listSegs(PinpointClient pinpoint, String appId) { try { GetSegmentsRequest request = GetSegmentsRequest.builder() .applicationId(appId) .build(); GetSegmentsResponse response = pinpoint.getSegments(request); List<SegmentResponse> segments = response.segmentsResponse().item(); for (SegmentResponse segment : segments) { System.out .println("Segement " + segment.id() + " " + segment.name() + " " + segment.lastModifiedDate()); } } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
  • For API details, see GetSegments in AWS SDK for Java 2.x API Reference.

Kotlin
SDK for Kotlin
Note

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

suspend fun listSegs(appId: String?) { PinpointClient { region = "us-west-2" }.use { pinpoint -> val response = pinpoint.getSegments( GetSegmentsRequest { applicationId = appId }, ) response.segmentsResponse?.item?.forEach { segment -> println("Segement id is ${segment.id}") } } }
  • For API details, see GetSegments in AWS SDK for Kotlin API reference.

For a complete list of AWS SDK developer guides and code examples, see Using Amazon Pinpoint with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.