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.

Request
Type POST
Address http://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: 'http://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 http://opn.im/api/qr_for_short_url_code/{code}

Example:

http://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 http://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: 'http://opn.im/api/visits/' + statsCode,
                success: function (response) {
                    console.log("Response : ", response);
                }
            });

Visits timeline for the selected period.

Request
Type GET
Address http://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: 'http://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 http://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: 'http://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 http://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: 'http://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 http://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: 'http://opn.im/api/link_status/' + statsCode,
                success: function (response) {
                    console.log("Response : ", response);
                }
            });