﻿<a id="push_notification_reporter_webservice"></a>

# Push Notification Reporter

## Overview

This web service may be used to collect reports about received push notifications. When configured, the web service is
called each time a push notification is received and it reports the push notification to the server.

It can be used to create some automated test which sends push notification to a device and wait for the device to
report that the push has been successfully received or to collect statistics about push delivery success rate.

Push notifications are sent via Acrobits Push Notification Mediator (pnmediator) server. For instructions on how to
send pushes, see [HTTP Push](../../server/push/http_push.md).

## Parameters

Parameter templates for Push Notification Reporter can use any variables from [global](intro.md#global-params) and [account](intro.md#account-params)
scopes. Other parameters are taken from the received push notification, which is a key-value dictionary. The keys may
be used as placeholders which will be replaced by the appropriate values.

Unfortunately, the structure of the push notifications do not follow any well-defined, strict format for historical
reasons. The following keys may be useful for detecting the type of push notification.

### `pushId` { .reference-entry }

If not empty, the received push was sent as a response to PUSH-TEST.

### `s` { .reference-entry }

If not empty, the received push is a notification about incoming call. `c` contains the callee.

### `sm` { .reference-entry }

If not empty, the received push is a notification about incoming text message.

### `s_missed` { .reference-entry }

Indicates missed call notification.

### `type` { .reference-entry }

If not empty, it specifies other push types.

## Configuration

The following [Account XML](../account/account.md) keys are relevant for Push Notification Reporter configuration:

### `pushNotificationReporterUrl` { .reference-entry }

Contains the URL, including URL scheme, of the web service, possibly also with query string.

Example (with query-string):

```
https://example.com/pushReceived/?username=%account[username]%&pushTestId=%pushId%
```

### `pushNotificationReporterPostData` { .reference-entry }

If filled in, the app will use POST request to report the token.

Example (for application/x-www-form-urlencoded):

```
username=%account[username]%&pushTestId=%pushId%
```

Example (for application/json):

```json
{ "username" : "%account[username]%", "pushTestId" : "%pushId%" }
```

### `pushNotificationReporterContentType` { .reference-entry }

Specifies the value of Content-Type header to be sent in the request. If not specified, the app will default to
`application/x-www-form-urlencoded`

## Response

The response will be considered successful if the HTTP response code is 2xx. Any responses which have other
response code are silently ignored and the app will not retry the request.

There are no response values expected, so the body of the response is not parsed or processed in any way.

## Examples

### GET method

request:

```http
GET /pushReceived/?username=johndow&pushTestId=aELTLURy HTTP/1.1
Host: example.com
Connection: close
Cache-Control: max-age=0
User-Agent: CloudSoftphone/1.5.6
```

response:

```http
HTTP/1.1 200 OK
Date: Sun, 15 Mar 2015 00:46:17 GMT
Server: Apache/2.4.7 (Ubuntu)
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
```

### POST method, JSON

request:

```http
POST /pushReceived/johndow/ HTTP/1.1
Host: example.com
Connection: close
Cache-Control: max-age=0
User-Agent: CloudSoftphone/1.5.6
Content-Type: application/json
Content-Length: 183

{
    "pushTestId"    : "aELTLURy"
}
```

response:

```http
HTTP/1.1 200 OK
Date: Sun, 15 Mar 2015 00:46:17 GMT
Server: Apache/2.4.7 (Ubuntu)
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
```