OpenX Blog

Using the API: Advertise on my site

Tags: OpenX
by Chris Nutting on November 4th, 2008

The new OpenX API opens up a world of new possibilities for developers to automate common tasks associated with ad serving. Many publishers want to save time by getting direct advertisers to load up their own campaigns, so we’ve created a worked example showing how to use the API to create an ‘advertise on this site’ form.

By way of introduction, the OpenX ad server API is a web service which allows developers to control the ad server. It gives comprehensive access to the various objects in the ad server like advertisers, campaigns, zones, users… the list goes on. Loading up new campaigns and banners is a good example of how the API can be used.

The worked example builds a script which allows a user to enter details, upload an image file and have this data automatically captured into OpenX. It shows the core processes and functions necessary to allow a user to complete a simple form to load a campaign/banner created in your OpenX installation, ready for linking to your site.

The script could be extended in various ways to better suit your business. One logical next step would be to use the API’s getStats methods at the end of your billing cycle to gather statistics to feed into your invoicing/billing system.

Try the code for yourself, we’d love to see how you extend and improve it.

Using the API: Advertise on my site.

1 Comment »

  1. Thanks for Sharing, the only thing that I see is that you have to use openx alongside with this… I’m something similar and here is a piece of it using ZendFramework.. and without the openX helpers

    [code]
    set_include_path(get_include_path(). PATH_SEPARATOR . dirname(dirname(__FILE__)) . ‘/library’);
    require_once “Zend/XmlRpc/Client.php”;
    require_once “constants.php”;

    private function connect($requestUrl) {
    //Establish Connection
    $this->con = new Zend_XmlRpc_Client(OX_URL . $requestUrl . “.php”);
    }

    /**
    * Initialize a server connection with the XmlRpc Service
    * @param $user string user name
    * @param $password string user password
    * @return string phpads session token
    */
    function login($user, $password) {
    //Call service
    $this->connect ( ‘LogonXmlRpcService’ );

    //Initialice Session handler
    $this->session = $this->con->call(’logon’, array (
    new Zend_XmlRpc_Value_String($user),
    new Zend_XmlRpc_Value_String($password),
    ));

    if ($this->session) {
    return $this->session;
    } else {
    return false;
    }
    }

    //And then some advertiser fun

    $this->connect( ‘AdvertiserXmlRpcService’ );

    //Here we create an empty advertiser without any users
    //@TODO: Add Advertiser validation
    $advertiserId = $this->con->call(’addAdvertiser’,array(
    new Zend_XmlRpc_Value_String($this->session),
    new Zend_XmlRpc_Value_Struct(array(
    “advertiserName” => $input['clientCompany'],
    “agencyId” => DEFAULT_MANAGER //Default Agency
    ))
    ));

    Hope this helps!!!

    Comment by hertzel — November 4, 2008 @ 1:48 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment