Basics

muj.skrz.cz provides RESTful JSON API.

  • All communication takes place via HTTPS standard. HTTP is simple text protocol with S for Secure at the end = this means API communication is encrypted and can't be eavesdroped by any potential attacker.

  • API is not state based, it works on request-response principle. Every request sent to API is independent on previous or next requests.

  • Every data source (so called resource) presents a specific URL. Resource can be used for various actions with HTTP protocol. Request GET provides data from a resource. POST creates new resource. PUT changes resource to specific URL. DELETE deletes specific resource. URL of resources are stated without API root in the most cases.

  • Data are sent in JSON standard, all answers have header set to Content-Type: application/json. Same is expected from input data from requests.

Security

As stated above, communication is encrypted via HTTPS; potential attackers cannot eavesdrop sensitive data which are being exchanged between muj.skrz.cz API and you.

Authentication is managed by HTTP basic auth and header Authorization. User name (your access e-mail) and password for API is same as your muj.skrz.cz log in details.

For example, user name michal@skrz.cz and password daisy are chained with colon : and coded in Base64. It creates so called basic cookie, in this case ZnJhbnRhQHNrcnouY3o6c2VkbWlrcmFza2E=. Input it with designation Basic auth, and header Authorization:

Authorization: Basic ZnJhbnRhQHNrcnouY3o6c2VkbWlrcmFza2E=

Usually it is taken care of by your library (for example PHP curl, as follows) - set it just for usage of HTTP basic auth and user name with password.

API root

URLs are stated relatively to so called API root, which is:

https://muj.skrz.cz/api/v2

For example if you have resource /campaigns, its absolute URL is https://muj.skrz.cz/api/v2/campaigns.

Examples

Curl

The easiest way how to test muj.skrz.cz API is to use CLI tool curl, for example resource statement /campaigns:

$ curl -u michal@skrz.pl:daisy -X GET https://muj.skrz.cz/api/v2/campaigns?pretty
{
    "data": [
        {
            "id": 109999,
            "title": "Michaels travel agency",
            "slug": "FRAD000001",
            "publisher": {
                "id": 1,
                "title": "Skrz.cz"
            },
            "uri": "/api/v2/campaigns/109999"
        }
    ]
}

Notice the trick used with query parameter ?pretty.

Without it JSON answers would get back without white characters, purely out of economical reasons, so you can use it in production deployment. On the other hand, during testing it would be a nonsense to query one long unformatted string of characters. Query parameter ?pretty provides you with readable formatted JSON answer.

PHP

Similar to JSON you can send your query in PHP:

<?php
$username = "michal@skrz.cz";
$password = "daisy";

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_URL, "https://muj.skrz.cz/api/v2/campaigns");
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
$response = curl_exec($ch);
if ($response === false) {
    $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    throw new \RuntimeException("Request failed.", $statusCode);
} else {
    $response = json_decode($response);
    // work with $response
}

Example of query with full body - Nutné uvést příklad:

<?php
$username = "michal@skrz.cz";
$password = "daisy";
$payload = array(
    "clickCommission" => 1.6,
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_URL, "https://muj.skrz.cz/api/v2/campaigns/109999/promo/12345");
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
$response = curl_exec($ch);
if ($response === false) {
    $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    throw new \RuntimeException("Request failed.", $statusCode);
} else {
    $response = json_decode($response);
    // work with $response
}

Collection

If outcome of API resource is a collection of elements, it's always packed in JSON container and locked with data, for example GET /campaigns/{campaign}:

$ curl -u michal@skrz.cz:daisy -X GET https://muj.skrz.cz/api/v2/campaigns?pretty
{
    "data": [
        {
            "id": 109999,
            "title": "Michaels travel agency",
            "slug": "FRAD000001",
            "publisher": {
                "id": 1,
                "title": "Skrz.cz"
            },
            "uri": "/api/v2/campaigns/109999"
        }
    ]
}

Paging

If collection of elements is too big to fit into an answer, it gets paged. Paged answer has beside the key data also key for pagination, for example GET /campaigns/{campaign}/promo:

$ curl -u michal@skrz.cz:daisy -X GET https://muj.skrz.cz/api/v2/campaigns/109999/promo?pretty
{
    "data": [
        {
            "id": 123456,
            "title": "Michaels great summer vacation",
            "remoteItemId": "1",
            "dealId": 123456,
            "leafletId": null,
            "clickCommission": 10.5,
            "conversionPercent": 0.030,
            "published": true,
            "uri": "/api/v2/campaigns/144/promo/661294"
        },
        ...
    ],
    "pagination": {
        "next": "/api/v2/campaigns/FRAD000001/promo?pretty&limit=100&offset=100"
    }
}

Paging is managed by query parameters limit and offset. Its titles speak for themselves.

  • limit - sets maximum number of elements in an answer. Maximum limit of items you can select per paged answer is 100.
  • offset - how many items you want to skip at the beginning before limit is applied.

Skrz.cz s.r.o. (2024) Všeobecné obchodní podmínky | Pravidla pro zveřejňování nabídek