anamica
anamica

Reputation: 29

Bluemix Push Notification with userID

I am using the latest Bluemix Push Notification service. I'm using the MFPPush API to register the device (Android).

Here is my code snippet:

var success = function(message) 
{ 
    console.log("Success: " + message);
    alert("Reg Device: " + message);
};
var failure = function(message) 
{ 
    console.log("Error: " + message); 
    alert("Error: " + message);
};
MFPPush.registerDevice({}, success, failure);
var notification = function(notification)
{
    // notification is a JSON object.
    alert(notification.message);
};
MFPPush.registerNotificationsCallback(notification);

The success message contains the following information:

Token:APA91bFtkSr59Zxlr52HU****Uij
UserId: ""
DeviceId: g5c6d98f-0867-3fd1-a353-15bcdef675a2

When I send the notification, my device receives the message.

The Swagger REST API shows that I can arbitrarily give some token, userId and deviceId:

{
  "deviceId": "TestDeviceId",
  "platform": "G",
  "token": "************",
  "userId": "Joe"
}

How do I get the "TestDeviceId", and how do I get the "token"? I don't see any API to get that information.

Upvotes: 1

Views: 239

Answers (2)

pradeep sg
pradeep sg

Reputation: 193

@anamica (a) Allow userId parameter to be passed along with the MFPPush registration like MFPPush.register({"userId": "AUniqueUserId"}, success, failure) (b) Add an additional parameter to the target "userIds" (array). This enhancement has been done, you can give a try by updating the latest SDK.

Upvotes: 0

joe
joe

Reputation: 2488

Note: You should probably just use the Client SDK to register as it handles all of this in the background--automatically assigning each device a unique ID. You shouldn't explore this unless you know what you're doing. There isn't a really a reason for trying to manually set the deviceID.

When you register a device for the Push Notifications service, you set these values in the body of the POST request. On a successful call, it will return these values in the response. I'll do a demo of this later in the post.

register

You can also retrieve a list of the device registrations for the Push Notifications service. get devices

You can use that deviceId to retrieved detailed information about the device, send a specific push notification to that device, subscribe it to a tag and send push notifications to those devices, etc.

Swagger Documentation is here.


Regarding those values, you can put whatever you want in them when you register. Typically, these values would be set automatically by the Bluemix Mobile Android/iOS Client SDK when you do the register call. However, you could do this manually using the REST client.

For example:

Here, I'm registering a device:

registering

It registered successfully: successful response

This is what I get if I ask the Push Notifications service for information about my registered devices (for the "deviceId": "arandomdeviceid"):

querying

The Android BMS Core Client SDK sets this deviceId using a unique UUID from the device and hashing it with MD5.

You can look in here more more information about that.

Upvotes: 1

Related Questions