How to create JSON which uses a Deep Link action for use with PUSH API

In this UA dashboard, our team creates PUSH notifications and dispatches them to our iOS App.

Now I want to create a PHP script to automate sending of some PUSH notifications. The PHP script works fine (it is triggered via some condition in our database) - but I can't figure out how to replicate the JSON payload to trigger a a Deep Link Action.

In the App (in the debugger) when a PUSH is received that was sent via the UA Dashboard (and has a deep link associated) I see a payload which looks like (after being converted to a NSDictionary of course).

{
    "com.urbanairship.payload" =     {
        "^d" = "pannaapp://classes";
        "_" = "ad8b930e-6053-43f3-92d4-753a0e14917c";
        aps =         {
            alert = "This is a test of Deep Link PUSH to the Classes tab. ";
        };
    };
    "com.urbanairship.user_notification_id" = "com.apple.UNNotificationDefaultActionIdentifier";
}

Here is the JSON payload I am sending now, from my PHP script. Note here I am using the "extra" data element to pass a custom property (which I call "content-id") - that value is detected by my app and translation into the app opening a certain screen.  But what I really want is for this JSON to mimic the payload which would be sent from the UA Dashboard if I had triggered the link from there - using a Deep Link, thus resulting in the payload shown (in part) above!

$json_payload =  "{ \"audience\": { \”Tag\” : \”PurchasedSubscriptionEnding\” }, \"notification\": { \"ios\": { \"alert\": \"REMINDER: You're close to completing your subscription.\", \"extra\": { \"content-id\": 20002 } } }, \"device_types\": [ \"ios\" ]}";

Where do I put the whole "com.apple.UNNotificationDefaultActionIdentifier" thing - or do I really need that? How do I encode the "com.urbanairship.payload" in the JSON?

Thanks to anyone who can offer any guidance - like maybe a link to a page in the docs which actually shows how to do this using the API? 

Jordan.

 

 

Didn't find what you were looking for?

New post

Comments

3 comments

  • Thank you for posting your question in our Community Forum and for including the example JSON.

    If I understand correctly, you are wanting to send a push notification to an iOS application with a Deep Link included. Through the API, Deep Links are defined through the action object, specifically an open.

    Here is an example using the code you provided:

    {
       "audience":{
          "tag": "PurchasedSubscriptionEnding" 
       },
       "notification":{
          "ios":{
             "alert": "REMINDER:You're close to completing your subscription.",
             "extra":{
                "content-id":20002
             },
            "actions": {
                "open": {
                     "type": "deep_link",
                     "content": "pannaapp://classes"
                }
            }
          }
      },
       "device_types":[
          "ios"
       ]
    };
    

    Now using Action Mappings, the actions object can be shortened to:

    {
       "actions": {
            "app_defined": {
                 "^d": "pannaapp://classes"
            }
       } 
    }

    The other line you inquired about is not needed:

    "com.urbanairship.user_notification_id" = "com.apple.UNNotificationDefaultActionIdentifier";

    Comment actions Permalink
  • Hey thanks Brian! I had pretty much come to this conclusion about 2 hours after I posted this question, but i have not tried it yet. Really appreciate your response re: the user_notification_id as well, wasn't sure what to do with that. Thanks again.

     

     

    Comment actions Permalink
    0
  • That example above doesn't work. Actions cannot be on that level. I solved it with this approach:

    {
    "audience": {
    "tag": "flooble"
    },
    "notification": {
    "actions": {
    "app_defined": {
    "^d": "buzz://foo/bar"
    }
    },
    "ios": {
    "alert": "example alert"
    },
    "android": {
    "alert": "example alert"
    }
    },
    "device_types": [
    "ios",
    "android"
    ]
    }
    Comment actions Permalink
    0

Please sign in to leave a comment.