-
Notifications
You must be signed in to change notification settings - Fork 886
Polr Self Hosted API Documentation
Docs for legacy 1.x only -- for documentation regarding Polr 2.x, see docs.polr.me
All API calls should be directed to /api.php
.
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 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.
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).
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).
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
.
<?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";
?>
import requests
res = requests.get('http://PATHTOPOLR/api.php?apikey=key&action=shorten&url=http://google.com')
shortened_url = res.text