myPOS REST API provides all CRUD (Create, Read, Update, Delete) functionalities for webhooks. The Content-Type of the requests should be set to application/x-www-form-urlencoded and the generated oAuth Token must be included in an Authorization header for every HTTP request to the REST API.
Creating a webhook
The required parameters in order to create a webhook are payload URL and a secret, which will be used to sign the callback to your server.
curl -X POST \
https://webhook-api.mypos.com/v1/webhooks \
-H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'payload_url=https%3A%2F%2Fmywebsite.com%2Fwebhook-callback&secret=myrandomgeneratedsecret'
import requests
requests.post(
url='https://webhook-api.mypos.com/v1/webhooks',
headers={
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
'Content-Type': 'application/x-www-form-urlencoded'
},
data=dict(
payload_url='https://mywebsite.com/webhook-callback',
secret='myrandomgeneratedsecret'
)
)
const request = require("request");
const options = {
method: 'POST',
url: 'https://webhook-api.mypos.com/v1/webhooks',
headers: {
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
payload_url: 'https://mywebsite.com/webhook-callback',
secret: 'myrandomgeneratedsecret'
}
};
request(options, (error, response, body) => {
});
<?php
$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/webhooks');
$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(
'payload_url' => 'https://mywebsite.com/webhook-callback',
'secret' => 'myrandomgeneratedsecret'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
{
"webhook": {
"created_on": "Mon, 15 Apr 2019 07:50:54 GMT",
"id": "647f091e-b4b5-423e-9dd2-58c832ebb793",
"is_active": true,
"payload_url": "https://mywebsite.com/webhook-callback",
"secret": "myrandomgeneratedsecret"
}
}
List webhooks
Fetching a single webhook or all webhooks is fairly straightforward. All you need to do send an HTTP GET request to the corresponding endpoint:
curl -X GET \
https://webhook-api.mypos.com/v1/webhooks \
-H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
import requests
requests.get(
url='https://webhook-api.mypos.com/v1/webhooks',
headers={
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
}
)
const request = require("request");
const options = {
method: 'GET',
url: 'https://webhook-api.mypos.com/v1/webhooks',
headers: {
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
}
};
request(options, (error, response, body) => {
});
<?php
$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/webhooks');
$request->setMethod(HTTP_METH_GET);
$request->setHeaders(array(
'Authorization' => 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
{
"webhooks": [
{
"created_on": "Thu, 11 Apr 2019 07:07:58 GMT",
"id": "6217960c-2a2e-4188-9025-af11abf47d5e",
"is_active": true,
"payload_url": "https://mywebsite.com/webhook-callback",
"secret": "myrandomgeneratedsecret"
}
],
"pagination": {
"page": 1,
"size": 20,
"total": 1
}
}
More detailed information about a webhook can be requested by passing the webhook’s ID as an URL parameter
curl -X GET \
https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e \
-H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
import requests
requests.get(
url='https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e',
headers={
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
}
)
const request = require("request");
const options = {
method: 'GET',
url: 'https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e',
headers: {
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
}
};
request(options, (error, response, body) => {
});
<?php
$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e');
$request->setMethod(HTTP_METH_GET);
$request->setHeaders(array(
'Authorization' => 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
{
"webhook": {
"created_on": "Thu, 11 Apr 2019 07:07:58 GMT",
"events": [
{
"id": "7db45365-2478-480e-bf34-f6f315f0c0bd",
"name": "pos.payment.completed"
}
],
"is_active": true,
"payload_url": "https://google.com",
"secret": "Um6OcCJkN6tOXzUOOmcCyvOcKNFkuNpz"
}
}
Updating a webhook
At any time, a client can update any created webhook by sending an HTTP PATCH request to /hooks/:id. For instance, to disable a webhook but not delete it, we can update its active flag.
curl -X PATCH \
https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e \
-H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'payload_url=https%3A%2F%2Fmywebsite.com%2Fwebhook-callback&secret=myrandomgeneratedsecret'
import requests
requests.patch(
url='https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e',
headers={
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
'Content-Type': 'application/x-www-form-urlencoded'
},
data=dict(
payload_url='https://mywebsite.com/webhook-callback',
secret='myrandomgeneratedsecret'
)
)
const request = require("request");
const options = {
method: 'PATCH',
url: 'https://webhook-api.mypos.com/v1/webhooks',
headers: {
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
'Content-Type': 'application/x-www-form-urlencoded'
},
form: {
payload_url: 'https://mywebsite.com/webhook-callback',
secret: 'myrandomgeneratedsecret'
}
};
request(options, (error, response, body) => {
});
<?php
$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e');
$request->setMethod(HTTP_METH_PATCH);
$request->setHeaders(array(
'Authorization' => 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP',
'Content-Type' => 'application/x-www-form-urlencoded'
));
$request->setContentType('application/x-www-form-urlencoded');
$request->setPostFields(array(
'payload_url' => 'https://mywebsite.com/webhook-callback',
'secret' => 'myrandomgeneratedsecret'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
{
"webhook": {
"created_on": "Mon, 15 Apr 2019 07:50:54 GMT",
"id": "647f091e-b4b5-423e-9dd2-58c832ebb793",
"is_active": true,
"payload_url": "https://mywebsite.com/webhook-callback",
"secret": "myrandomgeneratedsecret"
}
}
Deleting a webhook
Deleting a webhook is no more difficult than fetching details for one. The only difference is the HTTP Method:
curl -X DELETE \
https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e \
-H 'Authorization: Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
import requests
requests.delete(
url='https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e',
headers={
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
}
)
const request = require("request");
const options = {
method: 'DELETE',
url: 'https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e',
headers: {
'Authorization': 'Bearer PLpC1CqVE9CYXolbGNBPqz0NYy8asFzG95XcToDsMP'
}
};
request(options, (error, response, body) => {
});
<?php
$request = new HttpRequest();
$request->setUrl('https://webhook-api.mypos.com/v1/webhooks/6217960c-2a2e-4188-9025-af11abf47d5e');
$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.