1
0
mirror of https://github.com/cydrobolt/polr.git synced 2024-11-09 11:42:28 +01:00
5 Polr Self Hosted API Documentation
Chaoyi Zha edited this page 2016-03-23 19:11:58 -04:00

Docs for legacy 1.x only -- for documentation regarding Polr 2.x, see docs.polr.me

API Endpoints

All API calls should be directed to /api.php.

API keys

You will need to insert into the table api with values apikey (the api key value), email (help you keep track of who the key was assigned to), valid (1 for valid, 0 for invalid). Once you have one, send it as the GET or POST variable apikey. This is required for every API call. If the API key is not sent, or is invalid, the API will return with the status code 401 (Unauthorized).

Actions

Actions are passed in the GET or POST variable action. There are currently two actions implemented:

  • shorten - shortens a URL
  • lookup - looks up the destination of a shortened URL

Actions take arguments, which are passed as GET or POST parameters.

shorten

The shorten action takes a single argument: url. This is the URL to shorten. The API will return with a plain text response containing a shortened URL.

Example: GET http://polr.me/api.php?apikey=key&action=shorten&url=http://google.com

Remember that the url argument must be urlencoded (unless it is passed as a POST parameter).

lookup

The lookup action takes a single argument: url. This is the URL to lookup. If it exists, the API will return with the destination of that URL. If it does not exist, the API will return with the status code 404 (Not Found).

Example: GET http://polr.me/api.php?apikey=hunter2&action=lookup&url=3

Remember that the url argument must be urlencoded (unless it is passed as a POST parameter).

Response

The API will respond in plain text. For lookup and shorten, it will reply with a URL, e.g http://polr.me/123 or http://alookedupurl.com .

Code Examples

PHP

<?php
$shortenedurl = file_get_contents('http://PATHTOPOLR/api.php?apikey=key&action=shorten&url=http://google.com');
echo "The shortened version of http://google.com is $shortenedurl";
?>

Python

import requests
res = requests.get('http://PATHTOPOLR/api.php?apikey=key&action=shorten&url=http://google.com')
shortened_url = res.text