OpenX API: Example XML-RPC Code to Get Campaign Month to Date Impressions


 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications OpenX API: Example XML-RPC Code to Get Campaign Month to Date Impressions
# 1  
Old 09-25-2011
OpenX API: Example XML-RPC Code to Get Campaign Month to Date Impressions

Here is an example of using the (unsupported) OpenX XML-RPC API to get the number of impressions served, month-to-date', for campaign number '123'.

PHP Code:
<?php

if (!@include('/website/openx287/lib/pear/XML/RPC.php')) {
      die(
'Error: cannot load the PEAR XML_RPC class');
}
$xmlRpcHost 'your.openx.server.com';
$webXmlRpcDir '/www/api/v1/xmlrpc';
$logonXmlRpcWebServiceUrl $webXmlRpcDir '/LogonXmlRpcService.php';
$campaignXmlRpcWebServiceUrl $webXmlRpcDir '/CampaignXmlRpcService.php';
$username 'your_openx_admin_user_name';
$password 'your_openx_password';

function 
returnXmlRpcResponseData($oResponse)
{
     if (!
$oResponse->faultCode()) {
          
$oVal $oResponse->value();
          
$data XML_RPC_decode($oVal);
          return 
$data;
     } else {
     die(
'Fault Code: ' $oResponse->faultCode() . "\n" .
         
'Fault Reason: ' $oResponse->faultString() . "\n");
     }
}

// login to openx api and print session id

$aParams = array(
                    new 
XML_RPC_Value($username'string'),
                    new 
XML_RPC_Value($password'string')
             );
$oMessage  = new XML_RPC_Message('logon'$aParams);
$oClient   = new XML_RPC_Client($logonXmlRpcWebServiceUrl$xmlRpcHost);
$oResponse $oClient->send($oMessage);
if (!
$oResponse) {
     die(
'Communication error: ' $oClient->errstr);
}
$sessionId returnXmlRpcResponseData($oResponse);
echo 
'User logged on with session Id : ' $sessionId '<br>';

// get  month-to-date served impressions for campaign 123

$campaignId 123;
$oStartDate date("Ym").'01T00:00:00';
$oEndDate =  date("c");
$aParams    = array(
                new 
XML_RPC_Value($sessionId'string'),
                new 
XML_RPC_Value($campaignId'int'),    
                new 
XML_RPC_Value($oStartDate'dateTime.iso8601'), 
                new 
XML_RPC_Value($oEndDate'dateTime.iso8601'),  
                );

    
$oMessage   = new XML_RPC_Message('campaignPublisherStatistics'$aParams);    
    
$oClient    = new XML_RPC_Client($campaignXmlRpcWebServiceUrl$xmlRpcHost);
    
$oResponse  $oClient->send($oMessage);
    
$CampaignStats   returnXmlRpcResponseData($oResponse);
    echo 
'Campaign '$campaignID 'Month-to-Date Impressions: ' $CampaignStats['0']['impressions'] . '<br>';

//logout

$aParams   = array(new XML_RPC_Value($sessionId'string'));
$oMessage  = new XML_RPC_Message('logoff'$aParams);
$oClient   = new XML_RPC_Client($logonXmlRpcWebServiceUrl$xmlRpcHost);
$oResponse $oClient->send($oMessage);
echo 
'User with session Id : ' $sessionId ' logged off<br>';


?>
Note: I posted this because the OpenX API code is not supported anymore; but many people still use OpenX and there are not many examples on how to use the API on the net.

See also: OpenX API: Example XML-RPC Code to Get Campaign Impressions
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with getting last date of previous month and first date of previous 4th month from current date

I have requirment to get last date of previous month and the first date of previous 4th month: Example: Current date: 20130320 (yyyymmdd) Last date of previous month: 20130228 (yyyymmdd) First date of previous 4th month: 20121101 (yyyymmdd) In my shell --date, -d, -v switches are not... (3 Replies)
Discussion started by: machomaddy
3 Replies

2. UNIX and Linux Applications

OpenX API: Example XML-RPC Code to Get Campaign Booked Impressions

Here is an example of using the (unsupported) OpenX XML-RPC API to get the number of booked impressions for campaign number '123'. <?php if (!@include('/website/openx287/lib/pear/XML/RPC.php')) { die('Error: cannot load the PEAR XML_RPC class'); } $xmlRpcHost =... (0 Replies)
Discussion started by: Neo
0 Replies

3. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies
Login or Register to Ask a Question