Opn.Im API Reference.

Overview.

This documentation describes the public RESTful API of Opn.Im. The Opn.Im API provides methods for creating short links, retrieving analytics data, and managing short links. The RESTful API uses JSON as the underlying data serialization mechanism. The documentation always refers to the latest version of the API. Using the API is free of charge.

Authorization.

You can use the API with or without an API key. If you use authorization you have the opportunity to get a list of the all links for your account as well as manage your short links in the dashboard. To get your API key go to the API section in the dashboard. Please note that we can add ads to the short links created by users without authorization in some cases.
To use authorization you should pass your API key in the http header api_key for each API method described above.

IMPORTANT: If you have created a short link using authorized API, then you can work with it only through an authorized API.

Code example (JS)
            //include JQuery first
            var rq = new Object();
            rq.url = "google.com"

            $.ajax
            ({
                type: "POST",
                url: 'https://opn.im/api/link_to_shorten',
                headers: { 'api_key': 'YOUR_API_KEY' },
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(rq),
                success: function (response) {
                console.log("Response : ", response);
            }
            });

Request
Type POST
Address https://opn.im/api/link_to_shorten
Request payload JSON

To create a short link you need to POST JSON with a single field:

Request object fields
url The long URL

Response contains the short URL itself, URL to the analytics dashboard and the short url code (you may use it to generate QR code):

Response object fields
shortUrl The short link
statisticUrl Private link to the analytics dashboard
code Short link code
statisticCode Analytics link code
Code example (JS)
            //include JQuery first
            var rq = new Object();
            rq.url = "google.com"

            $.ajax
            ({
                type: "POST",
                url: 'https://opn.im/api/link_to_shorten',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(rq),
                success: function (response) {
                    console.log("Response : ", response);
                }
            });

Generating QR code for your short link.

You may generate QR code for your short link using code parameter (see Creating a short link):

Request
Type GET
Address https://opn.im/api/qr_for_short_url_code/{code}

Example:

https://opn.im/api/qr_for_short_url_code/Cn4gq

Retrieving analytics for your short link.

To retrieve analytics data for the specific short link use statisticCode parameter (see Creating a short link). There are several API methods for receiving analytics data.

Number of visits for the entire time.

Request
Type GET
Address https://opn.im/api/visits/{statisticCode}
Response contains the total number of clicks for the short link:
Response object fields
visits Total number of clicks for the entire time
Code example (JS)
            //include JQuery first
            var statsCode = "K7S9stKPdwaQ7J0r";
            $.ajax
            ({
                type: "GET",
                url: 'https://opn.im/api/visits/' + statsCode,
                success: function (response) {
                    console.log("Response : ", response);
                }
            });

Visits timeline for the selected period.

Request
Type GET
Address https://opn.im/api/visits_timeline/{statisticCode}/{from}/{to}
The dates format is yyyy-MM-ddTHH:mm:ss (UTC). Response contains a key-value object that represents a number of clicks for each day in the specified period.
Response object fields
visitsByDate Key-value object (date->number of clicks)
Code example (JS)
            //include JQuery first
            var statsCode = "K7S9stKPdwaQ7J0r";
            var from = '2018-05-01T00:00:00';
            var to = '2018-10-01T00:00:00';
            $.ajax
            ({
                type: "GET",
                url: 'https://opn.im/api/visits_timeline/' + statsCode + '/' + from + '/' + to,
                success: function (response) {
                    console.log("Response : ", response);
                }
            });

Number of clicks for the selected period by metric.

There several types of metric available for this method:
Metric alias Description
BY_COUNTRY Number of visits by user country
BY_BROWSER Number of visits by browser name
BY_OS Number of visits by operation system
BY_DEVICE_TYPE Number of visits by device type (desktop, mobile etc)
BY_REFERER Number of visits by source name (for example: google.com)
BY_REFERER_TYPE Number of visits by source type (direct, search etc)
Request
Type GET
Address https://opn.im/api/visits_by_metric/{code}/{Metric alias}/{from}/{to}
The dates format is yyyy-MM-ddTHH:mm:ss (UTC). Response contains a key-value object that represents a number of clicks for each metric value in the selected time period.
Response object fields
visitsByKey Key-value object (metric value->number of clicks)
Code example (JS)
            //include JQuery first
            var statsCode = "K7S9stKPdwaQ7J0r";
            var from = '2018-05-01T00:00:00';
            var to = '2018-10-01T00:00:00';
            $.ajax
            ({
                type: "GET",
                url: 'https://opn.im/api/visits_by_metric/' + statsCode + '/BY_BROWSER/' + from + '/' + to,
                success: function (response) {
                    console.log("Response : ", response);
                }
            });

Disabling and enabling the short link.

You may disable or enable your short link using statisticCode parameter (see Creating a short link):

Request
Type POST
Address https://opn.im/api/link_status
Request payload JSON
Request object fields
linkStatsCode The same as statisticCode
active TRUE if the link is enabled
Code example (JS)
           //include JQuery first
            var rq = new Object();
            rq.linkStatsCode = "K7S9stKPdwaQ7J0r";
			rq.active = true;

            $.ajax
            ({
                type: "POST",
                url: 'https://opn.im/api/link_status',
                dataType: 'json',
                contentType: 'application/json',
                data: JSON.stringify(rq),
                success: function () {
                    console.log("Done");
                }
            });

You can also GET status of the short link:

Request
Type GET
Address https://opn.im/api/link_status/{statisticCode}
Response object fields
active TRUE if the link is enabled
created Create date
shortUrlCode Short URL code
longUrl A long URL associated with this short URL
Code example (JS)
            //include JQuery first
            var statsCode = "K7S9stKPdwaQ7J0r";
            $.ajax
            ({
                type: "GET",
                url: 'https://opn.im/api/link_status/' + statsCode,
                success: function (response) {
                    console.log("Response : ", response);
                }
            });

To retrieve short links for your account use links method:

Request
Type GET
Address https://opn.im/api/links/{pageNumber}
The parameter pageNumber means the page number in the list of all links for your account. For the first page use pageNumber = 1.
Response object fields
links An array of objects. Each object contains: creation date, status, short URL code, long URL, analytics link code.
currentPage Current page number in the list of all links for your account.
totalPages The total number of pages in the list of all links for your account.
totalLinks The total number of short links for your account.

IMPORTANT: You can use this method only with the API key. For more information see Authorization section.