Drupal 7 Push Notifications: How to register a device token using services

I recently published a module on drupal.org that allows site admins to send push notifications to users that have registered their mobile device tokens and got asked how users can register a device token. The Push Notifications module for Drupal 7 can be found here: http://drupal.org/project/push_notifications. Here’s a quick tutorial on how to register a token through the services interface.

  1. Navigate to the Services admin interface at admin/structure/services: http://cl.ly/3F1429021N2W2y1s2j15
  2. Add a new services endpoint. For this example, I’m going to create an endpoint called “mobile_data”. This will be the base URL for your services, e.g. http://www.yoursite.com/mobile_data. See http://cl.ly/0j3o0B102j1A1a46183C
  3. You should see your new endpoint listed at admin/structure/services: http://cl.ly/0U0f0p470S1e2J1o0A29. Click on “Edit Resources” for that endpoint
  4. On the “Resource” page for that endpoint, you will see a list of all resources. Make sure “push_notifications” and “create” underneath it is enabled: http://cl.ly/2m0C0Y393y0P2f3L3016
  5. Make sure to enable all parsing types you want, e.g. if you’re sending url-encoded data, make sure it’s enabled: http://cl.ly/1C3K3S3y372o140x1K1c

These are all the steps you need to take to enable your services endpoint. You can then register your device token at http://www.yoursite.com/mobile_data/push_notifications. You should use a POST on that URL and pass two arguments:

  • Token: The device token (argument name: ‘token’)
  • Device Type: The type of the device (argument name: ‘type’, options are either ‘ios’ for iOS devices or ‘android’ for Android devices

A very helpful tool is the Cocoa REST Client.