branded.tiny.cc
Sign up

REST API Documentation

Not seeing what you need? No problem, sometimes one size doesn't fit all. Our platform was designed to be flexible. Contact Us we'd love the chance to work out a custom solution.

General

This is v3 of TINYCC REST API. It conforms to the REST API concept.

API root URL: http://branded.tiny.cc/tiny/api/3/
HTTPs and HTTP supported. But HTTPs recommended.

Authentication: HTTP Basic. Use your username:api-key for user:password.
Example: johndoe:c2es9d56-045d-4d87-b3f2-419274f4e001
Please login to your account to manage api-key.

If you have problem using PATCH HTTP method, we support method override for POST calls via X-HTTP-Method-Override header.

Recommended encoding for request's payload - "application/json".
However "application/x-www-form-urlencoded" and "multipart/form-data" are also supported for POST requests. If you want to make PATCH (or other non POST) request with encoding other then "application/json", you should use POST method and set X-HTTP-Method-Override header.

GET-parameters should be "percent-encoded".

Responses always encoded with "application/json".

All date-time values in API are in UTC±00:00.

Inactive accounts can't access API. They will get error 1217.


Getting account info

GET /account

Input params: none

Example response:

{ "error": { "code": 0, "message": "" }, "account": { "user_id": "4274", "username": "johndoe", "custom_domain": "johndoe.com", "account_expiration_date": "2015-08-30 20:57:03", "subscription_plan": "Secure Plan (1 year)", "counters": { "urls": { "count": 13, "limit": 5000 }, "today_api_calls": { "count": 8, "limit": 500 }, "month_urls": { "count": 13, "limit": 500 } } } } Response contains information about different counters. These fields depend on server configuration and may vary from server to server.

Shortening URLs

POST /urls

Input params:

{ "urls": [ { "custom_hash": "mytiny", "long_url": "http://example.com", "note": "lots of notes...", "email_stats": false, "expiration_date": "2016-01-02", "tags":["group1"] } ] } All fields are optional except "long_url". Default values:

Example of successful response:

{ "error": { "code": 0, "message": "" }, "urls": [ { "hash": "mytiny", "long_url": "http://example.com", "short_url": "johndoe.com/mytiny", "total_clicks": 0, "unique_clicks": 0, "note": "lots of notes...", "email_stats": false, "expiration_date": "2016-01-02", "tags":["group1"], "links":{ "qr_small": ..., "qr_big": ... }, "error": { "code": 0, "message": "", "details": "" } } ] }

Example of shortening errors:

{ "error": { "code": 0, "message": "" }, "urls": [ { "long_url": "http://google.com", "custom_hash": "h", "error": { "code": 1215, "message": "Short URL is not correct or existed.", "details": "That Custom hash is already in use" } } ] }

In both cases (successful shortening or shortening errors) HTTP status code - 200 OK and top-level "error" block indicates no errors.
But inside "urls" array, some URLs may have individual error message. In above example, one URL was successfully shortened. And other URL was not shortened.

Normally our system allows creation of multiple different short links containing exactly the same long or destination URL. But it is also possible to avoid making any new, unique short hashes if the long url had been previously submitted.
When your API call doesn't specify a custom_hash it is possible to avoid duplication of long URLs by passing the optional parameter "disable_long_url_duplicates":

POST /urls?disable_long_url_duplicates=1

In this case, new records won't be created for existing long URLs. Records from previously created links will be returned instead.

If you specify custom_hash together with "disable_long_url_duplicates" parameter, three scenarios are possible:

    If custom_hash does not exist, new record will be created
    If custom_hash exists with same long URL, existing records will be returned
    If custom_hash exists with different long URL, error 1215 will be indicated

Reading URLs

GET /urls - get a batch (50) of most recent URLs. { "error": { "code": 0, "message": "" }, "urls": [ { "hash": "h", "long_url": "http://google.com", "short_url": "m.tiny.cc/h", "total_clicks": 0, "unique_clicks": 0, "email_stats": false, "note": "", "expiration_date": null, "tags":[], "links":{ "qr_small": ..., "qr_big": ... } }, { "hash": "g", "long_url": "http://yahoo.com", "short_url": "m.tiny.cc/g", "total_clicks": 0, "unique_clicks": 0, "email_stats": false, "note": "", "expiration_date": null, "tags":[], "links":{ "qr_small": ..., "qr_big": ... } }, . . . ], "page": { "results_count": 13, "total_count": 13, "offset": 0 } } HTTP status code - 200 OK

It is also possible to paginate URLs like this
GET /urls?offset=10&limit=20
Other supported parameters:
Example:
GET /urls?offset=5&limit=1&search=john&order_by=clicks

Read single URL:
GET /urls/[hash]

To read a group of URLs you need to pass a group of hashes in query parameter "hashes", separated with comma.
For example, lets pass a group of three hashes (a,b,c):
GET /urls?hashes=a%2Cb%2Cc

Each individual URL entry has "links" section listing locations of related resources.


Editing URLs

There are three styles to edit URLs.
First style - edit single URL.
PATCH /urls/[current_hash]

Input params:

{ "urls": [ { "custom_hash": "new_hash", "long_url": "http://example.com", "note": "new note", "email_stats": false, "expiration_date": "2016-01-02", "tags":["+new_tag","-old_tag"] } ] } All fields are optional.
Tags field contains instructions for adding and removing tags. Tags prefixed with "+" will be attached to URL. Tags prefixed with "-" will be detached from URL.

Second style - set same properties for many URLs.
URL hashes should be listed in "hashes" parameter and separated by comma.
PATCH /urls?hashes=a%2Cb%2Cc

Input params:

{ "urls": [ { "note": "collective note" } ] } The above call will set "note" property for URLs with hashes "a","b" and "c".

Third style - arbitrary edit many URLs
PATCH /urls

Input params:

{ "urls": [ { "hash": "a", "note": "polite note" }, { "hash": "b", "note": "creative note" }, { "hash": "c", "note": "boring note" } ] } In this case "hash" field is mandatory.

Response of all three styles have the same structure. And it is similar to the structure of POST call ("page" section is not included).

Deleting URLs

DELETE /urls/[hash]

Input params: hash - tiny hash associated with URL.
It is also possible to pass a group of hashes in query parameter "hashes", separated with comma.
For example, lets pass a group of three hashes (a,b,c):
DELETE /urls?hashes=a%2Cb%2Cc

Example response:

{ "error": { "code": 0, "message": "" } } HTTP status code - 200 OK

Stats

Reading click stats for individual URL:
GET /stats/[hash]

Example response:

{ "error": { "code": 0, "message": "" }, "stats": [ { "hash": "e", "total_clicks": 22, "unique_clicks": 1 } ] }
Resetting stats for individual URL:
DELETE /stats/[hash]

Input params: hash - tiny hash associated with URL.
It is also possible to pass a group of hashes in query parameter "hashes", separated with comma.
For example, lets pass a group of three hashes (a,b,c):
DELETE /stats?hashes=a%2Cb%2Cc

Example response:

{ "error": { "code": 0, "message": "" } } HTTP status code - 200 OK

Tags

Each URL may have tags attached to it. Tags have their own endpoint /tags. Tag labels are not case-sensitive.
GET /tags - read list of all existing tags

Example response:

{ "error": { "code": 0, "message": "" }, "tags": [ { "label": "banana" }, { "label": "apple" } ] }
POST /tags - create new tag (if it is not exist).

Input params:

{ "label": "pear" }

Example response:

{ "error": { "code": 0, "message": "" }, "tags": [ { "label": "pear" } ] }
PATCH /tags/[label] - edit (rename) existing tag.

Input params:

{ "label": "new_label" }

Example response:

{ "error": { "code": 0, "message": "" }, "tags": [ { "label": "new_label" } ] }
DELETE /tags/[label] - delete tag with given label.

For efficiency, many operations with URLs may be performed using tags. In this case, "hashes" query parameter should be omitted. And "tags" query parameter should be used.
Example of reading first 10 URLs tagged with label "fruit":
GET /urls?tags=fruit&limit=10
Tags parameter may be used for reading URLs, patching URLs, deleting URLs and deleting stats.
Tags parameter support complex syntax with logical operators and brackets. More info here.

Group Operations

Group operations with URLs are limited to a maximum number of items. Currently: 50.
If you exceed this limit, you will experience an error 1221.
This limitation doesn't apply to operations with usage of tags (PATCH, DELETE). It, for example, means, that you are allowed to delete a limited number of URLs listing their hashes in "hashes" parameter. But you can delete URLs, that conform with tags query all in single call.

Client libraries README file contains a "Mass shortening" reference which means group or "batch." There is no practical difference between "batch" and "not batch" operations. All operations are "batch". Batch can contain a single entity or multiple entities. For convenience, two different methods are shown in clients:
• shorten() to work with a single URL.
• mass_shorten() to work with arrays of URLs.
Both methods use the same API endpoint. And produce similar results.



Error Codes

0 -- '' (empty message string means OK)
101 -- 'Unknown error'
1102 -- 'Invalid username'
1204 -- 'Not a valid Short URL hash'
1206 -- 'URL you tried to shorten was invalid'
1215 -- 'Short URL is not correct or existed'
1216 -- 'URL you tried to shorten is not allowed'
1217 -- 'Access Denied'
1218 -- 'Short URL is not correct'
1219 -- 'Target server on cooldown'
1220 -- 'URLs limit has been reached'
1221 -- 'Exceeded limit of batch operation'
1300 -- 'Invalid API key'
1301 -- 'Invalid resource'
1302 -- 'Method not supported'
1303 -- 'API call limit reached'
1305 -- 'Missing input parameters'
1306 -- 'URL not found in DB'
1307 -- 'Wrong number of input parameters'
1308 -- 'HTTP error'
1309 -- 'Tag not found'
1310 -- 'Too big POST data'
1311 -- 'Invalid or duplicate tag label'
1312 -- 'Invalid date'

Example error response:

{ "error": { "code": 1300, "message": "Invalid API key" } } HTTP status code - 400 Bad Request.
Other 40x and 50x codes may be also used.

Client libraries

PHP


JavaScript