We decided to make the Search Rest Api public so anybody can use it as they like, if you would like some other kind of Api, please let us know. If we can we will accommodate your wishes.
So this are main instruction of the Api, this is the example url to call for the Search Api:
- http://www.sharedj.com/search/search-api.php?s=[SearchTerm]&apiKey=[ApiKey]&outputType=[Json/Xml]&resultNumber=[Number of Result]&mail=[Your Contact Mail]
The parameters in the parenthesis are mandatory and following a brief explanation:
- s=[SearchTerm] : The search string you want to pass to the service. Es “s=James Blunt”
- apiKey=[ApiKey] : At the moment it’s fixed and the value is “Beta”. Es “apiKey=Beta”
- outputType=[Json/Xml] : The format of the Api output. If you would like an Xml output you can use, “outputType=Xml”, if you would like a Json output you use “outputType=Json”
- resultNumber=[Number of Result] : The number of result you would like to have (Still not implemented). Es. “resultNumber=20″
- mail=[Your Contact Mail]: Contact mail. This is very important to updates or change of the service. Please use a valid email addres! Es. “mail=myname@mydomain.net”
For example a functioning url would be something like this: http://www.sharedj.com/search/search-api.php?s=u2&apiKey=Beta&outputType=Xml&resultNumber=10&mail=developer@domain.com
So you will have your Xml results ready to parse. Following a pasted a simple Php script that can help you out on create your search page.
This block will get the Feed and insert the various value:
<?php
//Api Key
$apiKey = ‘Beta’;
//Query String
$searchQuery = $_GET['s'];
//Number of the results I want to fetch
$resultNumber = 10;
//Build the Url
$searchUrlFeed = ‘http://www.sharedj.com/search/search-api2.php?s=’.$searchQuery.’&apiKey=’.$apiKey.’&outputType=xml&resultNumber=’.$resultNumber.”;
//retrieve the Xml with Simplexml_laod function and make them available as an Array
$results = simplexml_load_file($searchUrlFeed);
Following a function that will help us to parse the results:
//function to parse the xml
function SearchResults($results){
foreach($results as $info_lyric){
print ‘<div>
<div><a href=”‘.$info_lyric->link.’”>’.$info_lyric->title.’</a> | <a href=”http://www.sharedj.com/discography-biography/’.urlencode($info_lyric->artist).’”>’.$info_lyric->artist.’</a> | Album: ‘.$info_lyric->album.’</div>
‘.$info_lyric->lyric.’</div>’;};
};
Here how you print the result in case there are results or not:
if($searchQuery != ” && !empty($results)){SearchResults($results);}elseif($searchQuery != ” && empty($results)){print’There are not result for the query <b>’.$searchQuery.’</b>’;};