use of software.amazon.awssdk.services.pinpoint.model.CreateSegmentRequest in project aws-doc-sdk-examples by awsdocs.
the class CreateSegment method createSegment.
// snippet-start:[pinpoint.java2.createsegment.main]
public static SegmentResponse createSegment(PinpointClient client, String appId) {
try {
Map<String, AttributeDimension> segmentAttributes = new HashMap<>();
segmentAttributes.put("Team", AttributeDimension.builder().attributeType(AttributeType.INCLUSIVE).values("Lakers").build());
RecencyDimension recencyDimension = RecencyDimension.builder().duration("DAY_30").recencyType("ACTIVE").build();
SegmentBehaviors segmentBehaviors = SegmentBehaviors.builder().recency(recencyDimension).build();
SegmentDemographics segmentDemographics = SegmentDemographics.builder().build();
SegmentLocation segmentLocation = SegmentLocation.builder().build();
SegmentDimensions dimensions = SegmentDimensions.builder().attributes(segmentAttributes).behavior(segmentBehaviors).demographic(segmentDemographics).location(segmentLocation).build();
WriteSegmentRequest writeSegmentRequest = WriteSegmentRequest.builder().name("MySegment").dimensions(dimensions).build();
CreateSegmentRequest createSegmentRequest = CreateSegmentRequest.builder().applicationId(appId).writeSegmentRequest(writeSegmentRequest).build();
CreateSegmentResponse createSegmentResult = client.createSegment(createSegmentRequest);
System.out.println("Segment ID: " + createSegmentResult.segmentResponse().id());
System.out.println("Done");
return createSegmentResult.segmentResponse();
} catch (PinpointException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
return null;
}
Aggregations