Notifications API

You can send push notifications through our Notifications API from any application.

To do so, just send a post request (from any language) to:

https://myapppresser.com/[site-slug]/wp-json/ap3/v1/send

You must include the following in your request:

  • id: App ID
  • message: Notification message
  • key: Notifications key
  • title: (optional) title of the notification
  • page: (optional) page data to send user to a specific page when they open the app.
  • device_arns: (optional) array of device identifiers to send to specific devices  If omitted, the push will go to all subscribed devices.
  • segment: (optional) the ARN of the segment you'd like to send to. You can find this on your push notifications dashboard.

You can find your site slug, app id, and notifications key on your myapppresser.com dashboard by clicking on your app and then "Push Notifications" in the left sidebar.

Examples

jQuery

var siteslug = "scottsapp";
var api = "https://myapppresser.com/" + siteslug + "/wp-json/ap3/v1/send";
var mykey = "9087hjsdkfjnwoije-";
var mytitle = "My title";
var mymessage = "Hey there!";
var appid = "5";
var segmentArn = "arn:aws:sns:us-west-2:876904128607:myapp-Yo-asdf";

jQuery.ajax({
  method: "POST",
  url: api,
  data: { id: appid, message: mymessage, key: mykey, title: mytitle, segment: segmentArn }
})
.done(function( msg ) {
  console.log( msg );
});

If you want to send pushes to specific devices we recommend doing this  through WordPress, since device_arns are saved in user meta. If you'd like to look these up, use the key 'ap3_endpoint_arns' in user meta. For example:

<?php get_user_meta( 32, 'ap3_endpoint_arns', 1 ); ?>

To open a specific page in the app, you must send a serialized array of page data that looks like this:

<?php
$page = array(
    'title' => "My Page",
    'page_type' => "list", // or "custom"
    'slug'    => "my-page", // only for custom HTML pages
    'type'    => "apppages", // or null
    'url' => "http://mysite.com/page", // only for WordPress pages
    'list_route' => "http://mysite.com/wp-json/wp/v2/posts", // only for list pages
    'favorites' => "true", // or "false"
    'target' => "_blank" // only for external web links
    'list_display' => "default", // or "card"
    'show_slider' => "true", // or "false"
    'slide_route' => "http://mysite.com/wp-json/wp/v2/posts" // only if show_slider = true
);

$page = serialize($page);
// you would then send $page as 'page' in your request

For a full example, look in the AppPush plugin, file /inc/AppPresser_Notifications_Update.php, notification_send() function.

It's recommended that you send the notification through our WordPress plugin, or through the myapppresser.com dashboard if you have trouble formatting this data.

Specific Push Examples

AP3 Custom Page Push

<?php
$page = array(
   'title' => "My Page",
   'page_type' => "custom",
   'type'    => "apppages",
   'slug'    => "my-page", 
   'type'    => "apppages", // or null
);

$page = serialize($page);
// you would then send $page as 'page' in your request

List Page Push

<?php
$page = array(
'title' => "My Page",
'page_type' => "list",
'type'    => "apppages",
'list_route' => "http://mysite.com/wp-json/wp/v2/posts", // only for list pages
'favorites' => "true", // or "false"
'list_display' => "default", // or "card"
'show_slider' => "true", // or "false"
'slide_route' => "http://mysite.com/wp-json/wp/v2/posts" // only if show_slider = true
);

$page = serialize($page);
// you would then send $page as 'page' in your request

WordPress Page Push

<?php
$page = array(
'title' => "My Page",
'url' => "http://mysite.com/page", // only for WordPress pages
'target' => "_blank" // only for external web links
);

$page = serialize($page);
// you would then send $page as 'page' in your request