- AWS Code Sample demonstrates how to update several existing endpoints in a single call to the API.

/* * Copyright, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package com.example.pinpoint; import; import; import; import; import; import; import; import; import; import java.util.Map; import java.util.List; import java.util.ArrayList; import java.util.HashMap; public class AddExampleEndpoints { public static void main(String[] args) { final String USAGE = "\n" + "AddExampleEndpoints - demonstrates how to update several existing endpoints in a single call\n\n" + "Usage: AddExampleEndpoints <appId>\n\n" + "Where:\n" + " appId - the ID of the application to delete.\n\n" ; if (args.length < 1) { System.out.println(USAGE); System.exit(1); } String applicationId = args[0]; // Create a PinpointClient object PinpointClient pinpoint = PinpointClient.builder() .region(Region.US_EAST_1) .build(); updateEndpointsViaBatch(pinpoint, applicationId); } public static void updateEndpointsViaBatch( PinpointClient pinpoint, String applicationId) { try { List<String> myList = new ArrayList<String>(); myList.add("music"); myList.add("books"); Map myMap = new HashMap<String, List>(); myMap.put("attributes", myList); List<String> myNames = new ArrayList<String>(); myList.add("Richard"); myList.add("Roe"); Map myMap2 = new HashMap<String, List>(); myMap2.put("name",myNames ); EndpointUser richardRoe = EndpointUser.builder() .userId("example_user_1") .userAttributes(myMap2) .build(); // Create an EndpointBatchItem object for Richard Roe EndpointBatchItem richardRoesEmailEndpoint = EndpointBatchItem.builder() .channelType(ChannelType.EMAIL) .address("") .id("example_endpoint_1") .attributes(myMap) .user(richardRoe) .build(); List<String> myListMary = new ArrayList<String>(); myListMary.add("cooking"); myListMary.add("politics"); myListMary.add("finance"); Map myMapMary = new HashMap<String, List>(); myMapMary.put("interests", myListMary); List<String> myNameMary = new ArrayList<String>(); myNameMary.add("Mary "); myNameMary.add("Major"); Map maryName = new HashMap<String, List>(); myMapMary.put("name",myNameMary ); EndpointUser maryMajor = EndpointUser.builder() .userId("example_user_2") .userAttributes(maryName) .build(); // Create an EndpointBatchItem object for Mary Major EndpointBatchItem maryMajorsSmsEndpoint = EndpointBatchItem.builder() .channelType(ChannelType.SMS) .address("+16145550100") .id("example_endpoint_2") .attributes(myMapMary) .user(maryMajor) .build(); // Adds multiple endpoint definitions to a single request object. EndpointBatchRequest endpointList = EndpointBatchRequest.builder() .item( richardRoesEmailEndpoint) .item( maryMajorsSmsEndpoint) .build(); // Create the UpdateEndpointsBatchRequest UpdateEndpointsBatchRequest batchRequest = UpdateEndpointsBatchRequest.builder() .applicationId(applicationId) .endpointBatchRequest(endpointList) .build(); // Updates the endpoints with Amazon Pinpoint UpdateEndpointsBatchResponse result = pinpoint.updateEndpointsBatch(batchRequest); System.out.format("Update endpoints batch result: %s\n", result.messageBody().message()); } catch (PinpointException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }

Sample Details

Service: pinpoint

Last tested: 03/02/2020

Author: scmacdon-aws

Type: full-example