Revive AdServer (Formerly OpenX Source) API – Introduction: Part 1
We use Revive AdServer (Formerly OpenX Source) frequently at BlackRiver as the most open and customizable ad serving platform both for many of our clients and our own internal projects. When it comes toRevive AdServer (Formerly OpenX Source) API – there is almost nothing out there but a few blog posts and outdated code samples. We would really like to share our experiences (both positive and negative) withRevive AdServer (Formerly OpenX Source) API as we strongly believe that theRevive AdServer (Formerly OpenX Source) platform should remain easy accessible and open to the public.
As you might already know, theRevive AdServer (Formerly OpenX Source) API service allows us to gain remote control of pretty much the entire functionality of the ad serving platform.Revive AdServer (Formerly OpenX Source) provides us with two versions (v1 and v2) of the API. You can still find some minimal documentation on v1 version of the API, but it has been deprecated since OpenX Source 2.7, thus we are going to focus on v2. The API service is based on the RPC (criticized by many as being inferior to REST) protocol, so as an obvious solution, we decided to use the latest PHP XML_RPC2 library provided by PEAR (http://pear.php.net/package/XML_RPC2/). The installation is fairly straight forward, if you have PEAR already installed, simply run pear install XML_RPC2
Now with the XML_RPC2 library setup, let us look into a specific code example:
require_once 'XML/RPC2/Client.php'; $oxLogin = array("username"=>"admin","password"=>"admin_password"); $opts = array('prefix' => 'ox.'); $advertiserId = 3; $client = XML_RPC2_Client::create('http://domain.com/openx/www/api/v2/xmlrpc/', $opts); try { $sessionId = $client->logon($oxLogin['username'],$oxLogin['password']); $result = $client->getAdvertiser($sessionId,$advertiserId); print_r($result); $result = $client->advertiserDailyStatistics($sessionId,$advertiserId); print_r($result); $client->logoff($sessionId); } catch (XML_RPC2_FaultException $e) { // The XMLRPC server returns a XMLRPC error die('Exception #' . $e->getFaultCode() . ' : ' . $e->getFaultString()); } catch (Exception $e) { // Other errors (HTTP or networking problems...) die('Exception : ' . $e->getMessage()); } |
Even though the above code is fairly self-explanatory, there are a few things to take into consideration. The login credentials MUST be of the main account used on theRevive AdServer (Formerly OpenX Source) installation, creating a separate administrator account just for the API service is not going to work. The “ox.” prefix for the RPC service is default and does not need to be changed. In this example, we authenticate (login) with the API, and then use the sessionId to retrieve a specific advertiser’s information as well as the daily stats for that specific advertiser. The advertiserDailyStatistics function returns an array of all days in which the advertiser was active, if there is no specific date passed as one of the parameters.
In the next little while, we are going to post more articles on specificRevive AdServer (Formerly OpenX Source) API functions (perhaps even a full list with explanations – which was never provided by the formerly OpenX Source core team) and how to control Revive AdServer (Formerly OpenX Source) Advertisers, Publishers, Campaigns, Zones and Banners as well as customRevive AdServer (Formerly OpenX Source) delivery limitations plugins and integration with open-source platforms like WordPress.
Hi,
Thanks for this post and for sharing all of this valuable information.
A developer named Rade Popovic made a REST ‘wrapper’ that sites on top of the OpenX API to make all of the API functionality available through a REST interface. You can find it a http://www.openxsourcerestapi.com
Best regards, Erik Geurts – OpenX consultant
Issue – While creating campaign using “AddCampaign” method of “CampaignService”, we are setting the region to a specific country as Sweden (#198) through RegionStruct as a part of TargetingStruct. When we get the campaign data for the same campaign using “GetCampaign” method, we get the country id as 198. However, when logged in to http://www.ac.openx.com, we could not see country set to Sweden and it shows default option as “Target All Locations”.
What other ways we tried?
1) We tried setting specific country, but we faced the same challenge.
2) We raised this on OpenX market forum, but did not get any reply yet. Please see attached.
3) We tried sending separate additional tag for regional targeting while calling “AddCampaign” method, but did not work.
API Reference Used:
1) PDF documents shared by you on yammer (OpenX Market_API_1.pdf, OpenX Market_API_2.pdf).
2) http://openx.com/sites/default/files/images/openxmkt_api_ac.pdf This document is last updated on 21st Nov 2011.
[…] The package comes with a sample PHP client and examples of all possible REST calls included in the API. It makes the initial implementation a breeze – you never have to guess which parameters and what format you have to use in the API calls (unlike the default XML-RPC wrapper). […]
i want to use the openx api version 4.0 via c#.net.
I have consumer key and consumer secret key, now my only question is that what is the auth url we need to form for authenticating the user and then access api after that, like webspectator have it : http://wsp.webspectator.com/PublicServices/GetAutoMonetizerReportByDate?key=%5Baccountkey%5D&
dateStart=[yyyy-mm-dd]&dateEnd=[yyyy-mm-dd]&websites=[websites-public-key]
this sort of url i need to form for authentication of the user, since i am using c#.net there is no client library are available for .net, so i need to create my own library.