Yes Snipurl offers an API to registered users.
- Snipurl API uses HTTP and is "RESTful". You will need to use the POST method to create/update
a snip automatically and to get the detailed from an existing snipurl.
- You need an API key to use the API. Register on Snipurl.com and you will automatically see your
"API key" listed on the right hand side in ohe Settings page.
- Because we require the user ID, new snips will be automatically associated with that account and
can be managed as usual in the MANAGE SNIPS section. Look at the "snipOwner" parameter
in the code below.
1. To snip a URL with nickname and private key new
You can issue a POST request to the program: http://snipurl.com/site/getsnip -- the POST request should send the required information as indicated in blue highlight in the code below. Here is some sample code in PHP, for example, making use of the Curl library:
- <?php
// REQUIRED FIELDS
$sniplink = 'http://www.url.com'; // THE URL TO BE SNIPPED
$snipuser = 'MYUSERID'; // YOUR USER ID REQUIRED
$snipapi = 'MYAPI'; // FIND IN YOUR "SETTINGS" PAGE
// OPTIONAL FIELDS
$snipnick = 'mynickname'; // MEANINGFUL NICKNAME FOR SNIPURL
$sniptitle = 'My descriptive title'; // TITLE IF ANY
$snippk = ''; // PRIVATE KEY IF ANY
$snipowner = ''; // IF THE SNIP OWNER IS SOMEONE ELSE
$snipformat = ''; // DEFAULT RESPONSE IS IN XML, SEND "simple"
// FOR JUST THE SNIPURL
$snipformat_includepk = ""; // SET TO "Y" IF YOU WANT THE PRIVATE KEY
// RETURNED IN THE SNIPURL ALONG WITH THE ALIAS
//----------------------------------
// NO NEED TO EDIT BEYOND THIS POINT
//----------------------------------
$URL = 'http://snipr.com/site/getsnip';
$sniplink = rawurlencode($sniplink);
$snipnick = rawurlencode($snipnick);
$sniptitle = rawurlencode($sniptitle);
// POSTFIELD
$postfield = 'sniplink=' . $sniplink . '&' .
'snipnick=' . $snipnick . '&' .
'snipuser=' . $snipuser . '&' .
'snipapi=' . $snipapi . '&' .
'sniptitle=' . $sniptitle . '&' .
'snipowner=' . $snipowner . '&' .
'snipformat='. $snipformat. '&' .
'snippk=' . $snippk
;
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
// THIS IS MERELY FOR DISPLAY IN A BROWSER
// TO GET THE RESPONSE DATA, JUST USE $data
echo '<pre>', htmlentities($data), '</pre>';
?>
This will return a response with the snipped URL and some other basic details:
Note that the private keys will also be returned if you set it. Use the "<snipwithkey>" tag to
retrieve the snipurl that has the private key embedded in it (for people who still prefer
the old private key structure of Snipurl).
NOT INTERESTED IN XML, AND ONLY WANT THE SNIPURL?
- If the $snipformat is sent as "simple", the response would not be the standard XML and
instead only the snipped URL, without anything else.
- <?php
...
$snipformat = 'simple'; // DEFAULT RESPONSE IS IN XML, SEND "simple"
// FOR JUST THE SNIPURL
...
ONLY WANT THE SNIPURL BUT INCLUDING THE PRIVATE KEY?
- If the $snipformat is sent as "simple" and the $snipformat_includepk is set to "Y", the response will be just the snipurl including the private key in it, so clicking the snipurl will not require the pass code.
- <?php
...
$snipformat = 'simple';
$snipformat_includepk = 'Y';
...
2. Updating/Deleting an existing snipurl
You can use the snipaction variable to update an already existing URL. Note that in the case of an UPDATE request, sending the current nickname of the snipurl is mandatory (naturally, or we wouldn't know which snipurl you wish to update) and must be set in the snipcurrentnickname parameter.
Consider the following example (new information or highlighted fields are highlighted in this pink color) --
- <?php
// REQUIRED FIELDS
$sniplink = 'http://www.newurl.com'; // THE URL TO BE SNIPPED
$snipuser = 'MYUSERID'; // YOUR USER ID REQUIRED
$snipapi = 'MYAPI'; // FIND IN YOUR "SETTINGS" PAGE
// OPTIONAL FIELDS
$snipnick = 'new_nickname'; // MEANINGFUL NICKNAME FOR SNIPURL
$sniptitle = 'My descriptive title'; // TITLE IF ANY
$snippk = ''; // PRIVATE KEY IF ANY
$snipowner = ''; // IF THE SNIP OWNER IS SOMEONE ELSE
$snipformat = ''; // DEFAULT RESPONSE IS IN XML, SEND "simple"
// FOR JUST THE SNIPURL
// OPTIONAL FIELDS FOR USE IN AN UPDATE REQUEST
$snipaction = 'UPDATE'; // UPDATE? (Tries to create a new snip by default)
$snipcurrentnick = 'current_nick'; // REQUIRED, WHEN UPDATING
$snipresetcount = ''; // SET TO 'Y' TO RESET CLICK COUNTS TO 0
//----------------------------------
// NO NEED TO EDIT BEYOND THIS POINT
//----------------------------------
$URL = 'http://snipr.com/site/getsnip';
$sniplink = rawurlencode($sniplink);
$snipnick = rawurlencode($snipnick);
$sniptitle = rawurlencode($sniptitle);
// POSTFIELD
$postfield = 'sniplink=' . $sniplink . '&' .
'snipnick=' . $snipnick . '&' .
'snipuser=' . $snipuser . '&' .
'snipapi=' . $snipapi . '&' .
'sniptitle=' . $sniptitle . '&' .
'snipowner=' . $snipowner . '&' .
'snipformat=' . $snipformat . '&' .
'snipaction=' . $snipaction . '&' .
'snipcurrentnick=' . $snipcurrentnick . '&' .
'snipresetcount=' . $snipresetcount . '&' .
'snippk=' . $snippk
;
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
// THIS IS MERELY FOR DISPLAY IN A BROWSER
// TO GET THE RESPONSE DATA, JUST USE $data
echo '<pre>', htmlentities($data), '</pre>';
?>
This will return a response with the snipped URL and some other basic details:
To delete an existing snipurl, enter the action as "delete".
3. To get full details of a snipurl.. new
This is a new experimental functionality, added Oct 2008. You can issue a POST request to the program: http://snipurl.com/site/getsnipdetails -- the POST request should specify the "id" of the snipurl you wish to retrieve information, as indicated in blue highlight in the code below. Here is some sample code in PHP, for example, making use of the Curl library:
- <?php
// REQUIRED FIELDS
$snipid = 'being_short'; // THE SNIPURL ID
$snipuser = 'MYUSERID'; // YOUR USER ID
$snipapi = 'MYAPI'; // FIND IN YOUR "SETTINGS" PAGE
//----------------------------------
// NO NEED TO EDIT BEYOND THIS POINT
//----------------------------------
$URL = 'http://snipr.com/site/getsnipdetails';
$snipid = rawurlencode($snipid);
$snipuser = rawurlencode($snipuser);
$snipapi = rawurlencode($snipapi);
// POSTFIELD
$postfield = 'snipid=' . $snipid . '&' .
'snipuser=' . $snipuser . '&' .
'snipapi=' . $snipapi
;
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
// THIS IS MERELY FOR DISPLAY IN A BROWSER
// TO GET THE RESPONSE DATA, JUST PROCESS XML CONTAINED IN $data
echo '<pre>', htmlentities($data), '</pre>';
?>
And this is the response you will get from the above code:
OLD API, NOW DEPRECATED
To simply snip URLs
We provide a simple querystring feature. Point your application to the following URL:
http://snipr.com/site/snip?
&r = simple [will specify that all you want is a snip back]
&link = the url [required]
&title = title if any
&snipnick = nickname if any
&snippk = private_key if any
For example:
http://snipr.com/site/snip?r=simple&link=http://groups.google.com/&snipnick=google897
If successful, this will return only the snipped URL http://snipr.com/google897.
To get just the underlying long URL from snips
If you enter a snip and want to simply get the URL that it points to--
http://snipurl.com/resolveurl?id=<SnipID>
For example, http://snipurl.com/resolveurl?id=1n4x2 will spew out the underlying long URL, if it was not set as 'Private'.
P.S.For reasons of bandwidth and performance of our main service, we do not offer an RAS or SOAP API at this time.