The myPOS events allow clients to subscribe/unsubscribe for/from events, list current subscriptions and request a history of event notifications.

 

 

List all available events

Currently, the full list is only accessible from the REST API.

curl -X GET \
  https://webhook-api.mypos.com/v1/events \
  -H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
import requests

requests.get(
    url='https://webhook-api.mypos.com/v1/events',
    headers={
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
    }
)
const request = require("request");

const options = {
    method: 'GET',
    url: 'https://webhook-api.mypos.com/v1/events',
    headers: {
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
    }
};

request(options, (error, response, body) => {

});
<?php

$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/events');
$request->setMethod(HTTP_METH_GET);

$request->setHeaders(array(
  'Authorization' => 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

{
    "events": [
        {
            "id": "33bcd9a7-43e4-4c0c-a728-106210056b1a",
            "name": "pos.payment.completed"
        },
        {
            "id": "a96b8eb8-67ca-42b5-ab5f-fdc24011ef72",
            "name": "pos.payment.failed"
        },
        {
            "id": "31028c55-24f9-4cb6-b801-282b906647b9",
            "name": "pos.payment.cancelled"
        },
        {
            "id": "a81fd693-d897-4f66-9c7c-f92c01460dac",
            "name": "account.out-bank-transfer.initiated"
        },
        {
            "id": "2261350a-2db1-45a3-b60d-f2fdb0225600",
            "name": "account.out-bank-transfer.failed"
        },
        {
            "id": "f82c6caa-d052-4dd3-9044-5be41b36a466",
            "name": "account.out-bank-transfer.approved"
        }
    ],
    "pagination": {
        "page": 1,
        "size": 20,
        "total": 6
    }
}

 

 

Subscribe for an event

To subscribe for an event, it is required to provide the webhook id and the event id. If the client has a single webhook, the webhook id will not be required. The response will contain the id of the subscription. 

curl -X POST \
  https://webhook-api.mypos.com/v1/subscriptions \
  -H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'webhook_id=51fb484a-4003-4e0d-9635-ce9e4b9062cf&event_id=18491b67-75fc-4702-8f63-535e0b6c475f'
import requests

requests.post(
    url='https://webhook-api.mypos.com/v1/subscriptions',
    headers={
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    data=dict(
        webhook_id='51fb484a-4003-4e0d-9635-ce9e4b9062cfk',
        event_id='18491b67-75fc-4702-8f63-535e0b6c475f'
    )
)
const request = require("request");

const options = {
    method: 'POST',
    url: 'https://webhook-api.mypos.com/v1/subscriptions',
    headers: {
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    form: {
        webhook_id: '51fb484a-4003-4e0d-9635-ce9e4b9062cfk',
        event_id: '18491b67-75fc-4702-8f63-535e0b6c475f'
    }
};

request(options, (error, response, body) => {

});
<?php

$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/subscriptions');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'Authorization' => 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
  'Content-Type' => 'application/x-www-form-urlencoded'
));

$request->setContentType('application/x-www-form-urlencoded');
$request->setPostFields(array(
  'webhook_id' => '51fb484a-4003-4e0d-9635-ce9e4b9062cfk',
  'event_id' => '18491b67-75fc-4702-8f63-535e0b6c475f'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
  

{
    "subscription": {
        "created_on": "Mon, 15 Apr 2019 10:20:05 GMT",
        "event": "pos.payment.completed",
        "filter": null,
        "hook": {
            "created_on": "Mon, 15 Apr 2019 10:15:55 GMT",
            "id": "7d35a9ec-cad3-4f06-8ad7-2618c27dc64a",
            "is_active": true,
            "payload_url": "https://mywebsite.com/webhook-callback",
            "secret": "myrandomgeneratedsecret"
        },
        "id": "48497e81-652b-4d18-83a8-2feac3ecf9db"
    }
}

 

 

Update event subscription

You can update a subscription's filter property with either PUT or PATCH HTTP methods. Here is an example with PUT.

curl -X PUT \
  https://webhook-api.mypos.com/v1/subscriptions \
  -H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'filter=%7B%22tids%22%3A%5B%2290004889%22%5D%7D'
import requests

requests.put(
    url='https://webhook-api.mypos.com/v1/subscriptions',
    headers={
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    data=dict(
        filter=dict(
            tids=[
                '90004889'
            ]
        )
    )
)
const request = require("request");

const options = {
    method: 'PUT',
    url: 'https://webhook-api.mypos.com/v1/subscriptions',
    headers: {
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    form: {
        filter: {
            tids: [
                '90004889'
            ]
        }
    }
};

request(options, (error, response, body) => {

});
<?php

$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/subscriptions');
$request->setMethod(HTTP_METH_PUT);

$request->setHeaders(array(
  'Authorization' => 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
  'Content-Type' => 'application/x-www-form-urlencoded'
));

$request->setContentType('application/x-www-form-urlencoded');
$request->setPostFields(array(
  'filter' => '{"tids":["90004889"]}'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
  

{
    "subscription": {
        "created_on": "Thu, 11 Apr 2019 07:09:05 GMT",
        "event": "pos.payment.completed",
        "filter": {
            "tids": [
                "90004889"
            ]
        },
        "hook": {
            "created_on": "Thu, 11 Apr 2019 07:07:58 GMT",
            "id": "6217960c-2a2e-4188-9025-af11abf47d5e",
            "is_active": true,
            "payload_url": "https://google.com",
            "secret": "Um6OcCJkN6tOXzUOOmcCyvOcKNFkuNpz"
        },
        "id": "7db45365-2478-480e-bf34-f6f315f0c0bd"
    }
}

 

 

Unsubscribe from an event

curl -X DELETE \
  https://webhook-api.mypos.com/v1/subscriptions/ef082ef0-25e6-4fd5-a85b-c3855bb55577 \
  -H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
import requests

requests.delete(
    url='https://webhook-api.mypos.com/v1/subscriptions/ef082ef0-25e6-4fd5-a85b-c3855bb55577',
    headers={
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
    }
)
const request = require("request");

const options = {
    method: 'DELETE',
    url: 'https://webhook-api.mypos.com/v1/subscriptions/ef082ef0-25e6-4fd5-a85b-c3855bb55577',
    headers: {
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
    }
};

request(options, (error, response, body) => {

});
<?php

$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/subscriptions/ef082ef0-25e6-4fd5-a85b-c3855bb55577');
$request->setMethod(HTTP_METH_DELETE);

$request->setHeaders(array(
  'Authorization' => 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
 

Response is empty if no errors occur.

 

 

List event notifications

To get a list of notifications sent by myPOS based on events for which you have subscribed, you can use the following example.

curl -X GET \
  https://webhook-api.mypos.com/v1/notifications \
  -H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
import requests

requests.get(
    url='https://webhook-api.mypos.com/v1/notifications',
    headers={
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
    }
)
const request = require("request");

const options = {
    method: 'GET',
    url: 'https://webhook-api.mypos.com/v1/notifications',
    headers: {
        'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
    }
};

request(options, (error, response, body) => {

});
<?php

$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/notifications');
$request->setMethod(HTTP_METH_GET);

$request->setHeaders(array(
  'Authorization' => 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

{
    "notifications": [
        {
            "event": "pos.payment.completed",
            "payload": {
                "amount": 9.90,
                "currency": "GBP",
                "merchant_name": "myPOS Europe Ltd.",
                "pan": "*8516",
                "tid": 90008496,
                "timestamp": 1554980066
            },
            "response_code": 200,
            "retry_count": 0,
            "sent_on": "Thu, 11 Apr 2019 10:54:02 GMT",
            "url": "https://mypos.com"
        }
    ],
    "pagination": {
        "page": 1,
        "size": 20,
        "total": 3
    }
}

 

The response will contain following information:

  1. Event’s name
  2. Payload
  3. Sent on
  4. Response status
  5. Retry count