title: How to use Pinpoint send messages to specific devices using the Java AWS SDK for Pinpoint
body: <p>I have been able to get my mobile Android app to receive messages generated from the Pinpoint Campaign console (<a href="https://console.aws.amazon.com/pinpoint/home" rel="nofollow noreferrer">https://console.aws.amazon.com/pinpoint/home</a>) to a specific device by targeting the segment to a custom attribute that only that device has.  </p>
  
  <p>Pinpoint Campaign config</p>
  
  <ul>
  <li>Mobile push channel</li>
  <li>Standard campaign</li>
  <li>Segment defined using custom attributes, holdout 0%</li>
  <li>Silent notification</li>
  <li>Custom JSON</li>
  <li>Launch immediate</li>
  </ul>
  
  <p>Now I would like to implement this feature in my Java app using the SDK APIs and target the device's Pinpoint endpoint.</p>
  
  <pre><code>GetEndpointRequest getEndpointRequest = new GetEndpointRequest()
     .withApplicationId(appId)
     .withEndpointId(endpointId);
  GetEndpointResult endpointResult = getAmazonPinpointClient().getEndpoint(getEndpointRequest);
  
  DirectMessageConfiguration directMessageConfiguration =
    new DirectMessageConfiguration().withGCMMessage(new GCMMessage().withBody(body).withSilentPush(true).withAction(Action.OPEN_APP));
  AddressConfiguration addressConfiguration = new AddressConfiguration().withChannelType(ChannelType.GCM);
  
  MessageRequest messageRequest = new MessageRequest().withMessageConfiguration(directMessageConfiguration)
     .addAddressesEntry(endpointResponse.getAddress(), addressConfiguration);
  
  SendMessagesRequest sendMessagesRequest = new SendMessagesRequest()
     .withApplicationId(appId)
     .withMessageRequest(messageRequest);
  </code></pre>
  
  <p>The "body" is the same JSON I put in the Pinpoint Campaign console.  When I run this, I get back a DeliveryStatus of SUCCESSFUL but the device never receives the message.</p>
  
  <pre><code>{ApplicationId: MY_APP_ID,Result: {clrVUcv-AwA:APA91bHGXkxpDJiw5kOMROA2XTJXuKreMklq9jemHO_KGYTIw6w84Fw9zLv9waMgLgha61IR-kZxgmrnFu-OGp8l6WFgp4Wolh4oOvZwMobGYNgzivv3bGIK83t-e4hiLx1TTaEIeRdQ={DeliveryStatus: SUCCESSFUL,StatusCode: 200,StatusMessage: {"multicast_id":4803589342422496921,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1515105369948916%c551fa42f9fd7ecd"}]},}}}
  </code></pre>
  
  <p>I have also tried this via the AWS CLI:</p>
  
  <pre><code>aws pinpoint send-messages --application-id MY_APP_ID --message-request "{\"Addresses\":{\"clrVUcv-AwA:APA91bHGXkxpDJiw5kOMROA2XTJXuKreMklq9jemHO_KGYTIw6w84Fw9zLv9waMgLgha61IR-kZxgmrnFu-OGp8l6WFgp4Wolh4oOvZwMobGYNgzivv3bGIK83t-e4hiLx1TTaEIeRdQ\":{\"ChannelType\":\"GCM\"}},\"MessageConfiguration\":{\"GCMMessage\":{\"Body\":\"{\\\"message\\\":\\\"stuff\\\"}\",\"SilentPush\":true}}}"
  </code></pre>
  
  <p>with a similar result (get 200 status code and DeliveryStatus of SUCCESSFUL but the app never receives).  I tried using the "Direct" message in the AWS Pinpoint console but they do not seem to support the same format (forces Action and Title/Message instead of silent push message with custom JSON).</p>
  
  <p>Am I getting the endpoint incorrectly?  How do I translate the above campaign into a message?  I see there is a sendUserMessages() API call as well but that doesn't seem to be right one (I couldn't find where to specify the specific user endpoint)? </p>
  
  <p>The client receives the campaign via the registered Service:</p>
  
  <pre><code>public class PushListenerService extends GcmListenerService {
  
  @Override
  public void onMessageReceived(final String from, final Bundle data) {
      AWSMobileClient.initializeMobileClientIfNecessary(this.getApplicationContext());
      final NotificationClient notificationClient = AWSMobileClient.defaultMobileClient()
              .getPinpointManager().getNotificationClient();
  
      NotificationClient.CampaignPushResult pushResult =
              notificationClient.handleGCMCampaignPush(from, data, this.getClass());
  
  
      Log.e(LOG_TAG, " onMessageReceived - got messages"  + data);
  </code></pre>
  
  <p>Do GCM direct messages get sent through the same campaign method or do I have to register a different service to process these?</p>