Dave Crooke
Dave Crooke

Reputation: 676

Urban Airship push notification to multiple devices - does it work?

I have an application which needs to send messages to multiple specific users (but not the whole database) at a time, using the Urban Airship push notification.

Using their v3 /push API, it is possible to push a message to a single device, however using the advertised "or" syntax to specify a list of devices does not work. When I send the following JSON (but with valid device tokens :) to the /push API it returns HTTP status 500, so I think they might have a bug. Their test API at /push/validate accepts the same JSON and deems it OK.

I can of course call the API many times in a loop, passing one handset token at a time, but it's inefficient, and clearly the multi-device option was put there intentionally.

Has anyone gotten this to work?

{
  "audience": {
    "or": [
      {
        "apid": "3aec0ab4-92b1-4a6f-7218-61ea5753527c"
      },
      {
        "device_token": "8957de44dc3dcc7bc2e297162bb3f33108d1f5323dcc94b97d4038dcc9896d24"
      }
    ]
  },
  "notification": {
    "alert": "foo"
  },
  "device_types": "all"
}

Upvotes: 0

Views: 1169

Answers (1)

Eric
Eric

Reputation: 1293

Yes, I've got this working. I'm using their PHP library but the generated payload is

{
  "audience": {
    "or": [
      {
        "apid": "dab7e9af-fff2-4437-b6f7-299321654e20"
      },
      {
        "device_token": "10ecb5256e965151b73ea374afd3a8447258d6d057a52418736a6e26bb2f7d06"
      }
    ]
  },
  "notification": {
    "android": {
      "alert": "My App update",
      "delayWhileIdle": false,
      "extra": {
        "feedItemId": "332"
      }
    },
    "ios": {
      "alert": "My App update",
      "badge": "+1",
      "extra": {
        "feedItemId": "332"
      }
    }
  },
  "device_types": [
    "android",
    "ios"
  ]
}

Note, I've specifically specified the target device platforms as iOS and Android. Because of that I've got two specific child objects of the notification node, one for each platform I'm targeting. This might not be necessary if you are only using a simple notification object, but I wanted to be able to pass through values in the extra node that helps for deep linking into the app.

Upvotes: 1

Related Questions