Method for Working with Push Notifications

To work with push notifications, execute requests using the push API method (before executing the request determine user token):

curl -X GET '<IP address or DNS server name>/api/v1/push/tokens/' --header 'Authorization: Bearer <user token>' --header 'Accept: application/json'

The example of response:

{

  "received_date":"2020-10-30T10:58:04.414637Z",

  "device":{

    "id_string":"654654ghdfg5435",

    "is_active":true,

    "os_version":"iOS"

  },

  "token":"b34735aa4681cfe91616c775f3b9b8f7f410a3e7c79ed6a48dfd41907a13be23",

  "push_service":"Firebase"

}

curl -X POST '<IP address or DNS server name>/api/v1/push/tokens/add/' --header 'Authorization: Bearer <user token>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"token": {"value": "<token>","platform": "ios"}}'

curl -X POST '<IP address or DNS server name>/api/v1/push/tokens/add/' --header 'Authorization: Bearer <user token>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"token": {"service": "firebase", "platform": "android", "value": "<token>"}}'

The example of response:

{

  "status":"OK"

}

curl -X POST '<IP address or DNS server name>/api/v1/push/tokens/remove/' --header 'Authorization: Bearer <user token>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"tokens": ["<token>"]}'

The example of response:

{

  "status":"OK"

}

curl -X GET '<IP address or DNS server name>/api/v1/push/topics/' --header 'Authorization: Bearer <user token>' --header 'Accept: application/json'

The example of response:

[

  {

    "name":"topic",

    "description":"",

    "subscribed":true

  },{

    "name":"topic1",

    "description":"",

    "subscribed":false

  },{

    "name":"topic2",

    "description":"",

    "subscribed":false

  }

]

curl -X POST '<IP address or DNS server name>/api/v1/push/topics/subscribe/' --header 'Authorization: Bearer <user token>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"topics":["<topic 1 name>","<topic 2 name>",...,"<topic n name>"]}'

The example of response:

{

  "status":"OK"

}

curl -X POST '<IP address or DNS server name>/api/v1/push/topics/unsubscribe/' --header 'Authorization: Bearer <user token>' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"topics":["<topic 1 name>","<topic 2 name>",...,"<topic n name>"]}'

The example of response:

{

  "status":"OK"

}

curl -X POST '<IP address DNS server name>/api/v1/push/send/<template name>/user/<user name>/' --header 'Authorization: Bearer <user token>' --header 'Content-Type: application/json' -d '{"title": "<title>","body": "<body>"}'

The example of response:

{

  "status":"OK"

}

curl -X POST '<IP topic or DNS server name>/api/v1/push/send/<template name>/topic/<topic name>/' --header 'Authorization: Bearer <user token>' --header 'Content-Type: application/json' -d '{"title": "<title>","body": "<body>"}'

The example of response:

{

  "status":"OK"

}

When push notification is passed to a specific user or to all users, the request body contains the parameters specified in the template:

-d '{"title": "<title>","body": "<body>"}'

For example, the specified values of the title and body parameters correspond to the template as follows:

{

  "notification": {

    "title": "{{title}}",

    "body": "{{body}}"

  }

}

See also:

Server API | Setting Up Push Notifications