GetPriceResearch PHP/REST Tutorial
Printable Version
Last updated: 2008-01-02 14:19:56
Getting started with the DataUnison GetPriceResearch API

In this tutorial you will use PHP to write a GetPriceResearch call to get the average price for products on eBay based on the keywords in the title.
This tutorial shows how easy it is to use the DataUnison GetPriceResearch API.
When you complete the tutorial, you will have code that looks like this when it runs:
There are three steps:
  • Step 1: Set up and make the GetPriceResearch call
  • Step 2: Add code to parse and display the results
  • Step 3: Run the code
You can download all of the code used in this example: PricingAPISample.zip. You will need to substitute your production appid for "<YOUR APPID HERE>".

Step 1: Set up and make the GetPriceResearch call
Please join the eBay Developers Program. Note your Production appid so you can substitute it in this tutorial where it says "<YOUR APPID HERE>." This tutorial uses closed listing data from the last 30 days.
Please install Apache HTTP Server and install PHP 5. PHP 5 includes the SimpleXML extension. In this tutorial, the PHP sample file will be stored at the following location: C:Program FilesApache Software FoundationApache2.2htdocs.
To use this URL in the tutorial, you must substitute your production appid for "<YOUR APPID HERE>" and remove all spaces and new-line characters.
To create the initial code for your GetPriceResearch API call:
  1. Create a new file with the following text, which includes the first line of the PHP code. Save the file at C:Program FilesApache Software FoundationApache2.2htdocsMySample.php:
    <html>
    <head>
    <title>
    eBay Pricing Results for <?php echo $Query; ?>
    </title>
    </head>
    <body>
    
    <h1>eBay Pricing Results for <?php echo $Query; ?></h1>
    
    <?php echo $results; ?>
    
    </body>
    </html>
  2. Plan the values you will use for the GetPriceResearch input parameters.
    Field Description Expected Value Equivilant XML Field
    CallName * The name of the call you're trying to make. string -
    Version * The version of the call you're schema is based upon. The only valid value for this field is currently "2". integer Version
    AppID * The eBay Shopping API Application ID you wish to authenticate with. string RequesterCredentials.AppID
    QueryKeywords * The keywords you're searching for. string QueryKeywords
    EndTimeTo The last day in the period you wish to search. date EndTimeTo
    ResearchPeriod The length (in days) of the period you wish to search. integer ResearchPeriod
    Currency The currency you wish to view results in. currency Currency
    IncludeDailyStatistics Whether or not you wish to view daily statistic breakdowns. boolean IncludeDailyStatistics
    ChildCategoryID Search only specific category ids. integer ChildCategoryID
    ListingLimit Limit the number of listings used in the statistics. integer ListingLimit
    MinPrice Search only listings over a certain price. float MinPrice
    MaxPrice Search only listings under a certain price. float MaxPrice
  3. Add the following code directly after <?php. This code contains the GetPriceResearch input parameters from the step above, including the query keyword and your appid. This code prepares the sample to make the GetPriceResearch call.
    $AppID = '<YOUR APPID HERE>';  // APPID, needed for Pricing calls
    $SiteId = '0';  // Site used. Site ID 0 = US
    $Version = '2'; // API version
    $Query = 'toy boat'; // Keyword query
    
    $SafeQuery = urlencode($Query); // Make the query URL-friendly
    
    // Construct the GetPriceResearch REST call 
    $apicall = "http://open.api.dataunison.com/rest/?CallName=GetPriceResearch&AppID=$AppID&SiteId=$SiteId" .
               "&Version=$Version&ResearchPeriod=30&QueryKeywords=$SafeQuery";
    

Step 2: Add code to parse and display the results
In this step you will add code to store and then display the values returned.
  1. In MySample.php, after the last line above (where $apicall is set to a URL value), add the following code:
    // Load the call and capture the XML document returned by eBay API as an object
    $xml = simplexml_load_file($apicall);
    
    // Check to see if the XML response was loaded, else print an error
    if ($xml) {
    	$results = '';
    
    	if( $xml->Errors )
    	{
    		// If there was an error in the response, print a warning.
    		$results = "Uh oh, there was an error making the query!";
    	}
    	else
    	{
    		// Gather our statistics
    		$Statistics = $xml->Statistics;
    
    		$TotalSales = $Statistics->TotalSales;
    		$TotalSoldItems = $Statistics->TotalSoldItems;
    		$AverageSoldPrice = $Statistics->AverageSoldPrice;
    		$MinSoldPrice = $Statistics->MinSoldPrice;
    		$MaxSoldPrice = $Statistics->MaxSoldPrice;
    
    		$results .= "<b>Total Sales:</b> $TotalSales<br/>";
    		$results .= "<b>Total Sold Items:</b> $TotalSoldItems<br/>";
    		$results .= "<b>Average Sold Price:</b> $AverageSoldPrice<br/>";
    		$results .= "<b>Minimum Sold Price:</b> $MinSoldPrice<br/>";
    		$results .= "<b>Maximum Sold Price:</b> $MaxSoldPrice<br/>";
    	}
    }
    // If there was no XML response, print an error
    else {
    	$results = "Dang! Must not have got the XML response!";
    }
  2. Save the MySample.php file.

Step 3: Run the code
The MySample.php file is complete. Open the file in a browser (http://localhost/MySample.php).
The result should look similar to the following:
Congratulations! You have used the DataUnison GetPriceResearch API to retrieve research about items on eBay and display the results to a user.
For more information about our additional research APIs and tools, check out the DataUnison Developer Area documentation.

Final Notes
No Comments FoundPost A Comment 
Use of this Web site constitutes acceptance of the
DataUnison Terms and Privacy Policy.
Copyright © 2005-2008 DataUnison. All Rights Reserved.
eBay and the eBay Logo are Trademarks of eBay Inc.