23 Jul, 2009 in Programming by

.NET library for accessing the OpenX API

;

I’ve started work on a .NET library for manipulating an instance of OpenX 2.6+.

There’s quite a bit that this XML-RPC interface provides to developers. As such, I’ve only got the minimum of create, retrieve, update & delete methods implemented. There are more advanced methods for retrieving statistics which I’ haven’t begun work on yet. This library requires XMLRPC.NET.

So far, here is what my class has implemented:

  public OpenXApiV2(string endpointUrl, string username, string password)
  public string SessionId
  public void Logon()
  public bool Logoff()
  public int AddBanner(Banner newBanner)
  public Banner GetBanner(int bannerId)
  public bool ModifyBanner(Banner banner)
  public bool DeleteBanner(int bannerId)
  public Banner[] GetBannerListByCampaign(int campaignId)
  public int AddZone(Zone newZone)
  public Zone GetZone(int zoneId)
  public bool ModifyZone(Zone zone)
  public bool DeleteZone(int zoneId)
  public Zone[] GetZoneListByPublisher(int pubId)
  public void LinkBanner(int zoneId, int bannerId)
  public void UnlinkBanner(int zoneId, int bannerId)
  public void LinkCampaign(int zoneId, int campaignId)
  public void UnlinkCampaign(int zoneId, int campaignId)
  public int AddPublisher(Publisher newPub)
  public Publisher GetPublisher(int pubId)
  public bool ModifyPublisher(Publisher publisher)
  public bool DeletePublisher(int pubId)
  public Publisher[] GetPublishersByAgency(int agencyId)
  public int AddCampaign(Campaign newCampaign)
  public Campaign GetCampaign(int campaignId)
  public bool ModifyCampaign(Campaign campaign)
  public bool DeleteCampaign(int campaignId)
  public Campaign[] GetCampaignListByAdvertiser(int advertiserId)
  public int AddAgency(Agency newAgency)
  public Agency GetAgency(int agencyId)
  public bool ModifyAgency(Agency agency)
  public bool DeleteAgency(int agencyId)
  public Agency[] GetAgencyList()
  public int AddAdvertiser(Advertiser newAdvertiser)
  public Advertiser GetAdvertiser(int advertiserId)
  public bool ModifyAdvertiser(Advertiser advertiser)
  public bool DeleteAdvertiser(int advertiserId)
  public Advertiser[] GetAdvertiserListByAgency(int agencyId)
  public int AddChannel(Channel newChannel)
  public Channel GetChannel(int channelId)
  public bool ModifyChannel(Channel channel)
  public bool DeleteChannel(int channelId)
  public Channel[] GetChannelListByWebsite(int websiteId)
  public Channel[] GetChannelListByAgency(int agencyId)
  public int AddUser(User newUser)
  public User GetUser(int userId)
  public bool ModifyUser(User user)
  public bool DeleteUser(int userId)

I’ll continue implementing the remaining methods as I have time.

Download the OpenX.Net binary or OpenX.Net source code.

9/18/09, 1.1 – implemented LinkBanner, LinkCampaign, UnlinkBanner & UnlinkCampaign.

7/30/09 , 1.0 – initial release.

If you have any questions or suggestions, please leave a comment.

Share on Twitter

39 Responses so far | Have Your Say!

  1. Wavatar

    Indrani  |  April 5th, 2010 at 10:10 am #

    I am using your library to connect to OpenX API. But I am not being able to log into OpenX, as it throws an IllFormedXML Exception for some unknown reason.
    My code is:

    using DCC.OpenXClient;
    using DCC.OpenXClient.v2;
    using CookComputing.XmlRpc;

    protected void Page_Load(object sender, EventArgs e)
    {

    string Url = “”;
    string username = “”;
    string password = “”;

    OpenXApiV2 openxapi = new OpenXApiV2(“http://localhost/OpenX/www/api/v2/xmlrpc/LogonXmlRpcService.php”, “test@test.com”, “openx”);
    openxapi.Logon();
    }

    Please help. Do I need to do anything more than this?

    Thanks & Regards

  2. Wavatar

    Roger  |  April 5th, 2010 at 2:00 pm #

    @Indrani try just using: http://localhost/OpenX/www/api/v2/xmlrpc/ as the Endpoint URL.

    Also, your using this on OpenX 2.6+, correct?

  3. Wavatar

    Indrani  |  April 6th, 2010 at 11:04 am #

    Hi,

    Thanks. It worked.

    Regards,

  4. Wavatar

    Indrani  |  April 16th, 2010 at 9:44 am #

    hi,

    I have created zones and campaigns using DCC.OpenXClient.( DCC.OpenXClient.v2.Campaign c = new DCC.OpenXClient.v2.Campaign();
    )
    In campaign, I dont find any appropiate attribute to link campaign to zone.
    How do I link zones to campaigns/banners ?

    Regards,
    Indrani

  5. Wavatar

    Roger  |  April 16th, 2010 at 7:07 pm #

    @Indrani look at the LinkCampaign(int zoneId, int campaignId) method. That will bind the your banners/campaigns to a zone.

  6. Wavatar

    Indrani  |  April 16th, 2010 at 7:35 pm #

    hi,

    I cant find the LinkCampaign()method in campaign.
    DCC.OpenXClient.v2.Campaign c = new DCC.OpenXClient.v2.Campaign();
    c.??? could not find it.

    It will be very helpful if you kindly guide me.

    Thanks & Regards,
    Indrani

  7. Wavatar

    Roger  |  April 16th, 2010 at 8:35 pm #

    Sorry Indrani, I should have specified, the LinkCampaign method is on the OpenXApiV2 class.

  8. Wavatar

    Indrani  |  April 20th, 2010 at 1:12 pm #

    Hi,

    Thanks, I will try that.

    Currently,while adding a Publisher, the Web Url for the Publisher is not getting created.

    My Code:

    //PUBLISHER :
    Publisher newPub = new Publisher();
    newPub.publisherName = “My Example Website”;
    newPub.comments = “”;
    newPub.agencyId = 1;
    newPub.contactName = “John Doe”;
    newPub.emailAddress = “johnd@example.com”;
    newPub.website = “http://www.google.com”;
    newPub.publisherId = ox.AddPublisher(newPub);

    How do I add the Web URL ?

    Thanks & Regards,
    Indrani

  9. Wavatar

    Indrani  |  April 21st, 2010 at 5:18 am #

    Hi,

    After running the aforesaid code, when I go to OpenX, for the Publisher newly created the Web Url remains empty although other properties like name/contact/email are populated.
    How do I set the WebUrl as “newPub.website = “http://www.google.com”;” doesnt seem to work. 🙁

    Thanks & Regrards,

  10. Wavatar

    Roger  |  April 21st, 2010 at 1:33 pm #

    @Indrani, well after some digging it appears that this is a bug in the OpenX XML-RPC implementation. They aren’t pulling the value for website as they do the other fields that are populating correctly.

    Here’s a hack to try and get this to work if you really need it. It’s modifying the OpenX code so it will get wiped out if you do any updates plus I take no responsibility if it breaks something else 🙂

    Under your OpenX installation, open /lib/OA/Dll/Publisher.php

    At line 209 in my version, I’d insert a new line after as follows:
    $publisherData[“website”] = $oPublisher->website;

    I haven’t tested it but it appears that’s what’s missing to get the website data stored correctly.

  11. Wavatar

    Indrani  |  April 22nd, 2010 at 6:40 am #

    Hi,

    Thanks it worked.

    Regards,

    Indrani

  12. Wavatar

    Indrani  |  April 26th, 2010 at 10:57 am #

    Hi,

    With regard to Banner, could you please help me to map attributes like Alt Text / Keywords / Text below / Status Text etc.

    Banner banner = new Banner();
    banner. // I DON’T FIND ANY APPROPRIATE PROPERTIES TO MAP THE AFORESAID ATTRIBUTES

    Thanks & Regards,

    Indrani

  13. Wavatar

    Roger  |  April 27th, 2010 at 7:25 pm #

    Ho Indrani, it looks like the properties you’re looking for aren’t exposed through the OpenX XML-RPC interface.

    It would take a quite a bit more hacking up of their implementation (which would break after an upgrade) and an enhancement to my library to implement what you’re looking for.

    Sorry, I know that’s not what you want to hear.

    Regards,
    Roger

  14. Wavatar

    Indrani  |  April 29th, 2010 at 7:37 am #

    Hi,

    I just have your dlls. If you don’t mind can I extend your library ? Would you please give me your source code.

    Thanks & Regards,
    Indrani

  15. Wavatar

    Roger  |  May 6th, 2010 at 3:16 pm #

    Hi Indrani, the source code is now available to download. The link is in the post above next to the binary download link.

    Enjoy!

  16. Wavatar

    Indrani  |  May 10th, 2010 at 11:14 am #

    hi,

    Cannot create a Banner.

    DCC.OpenXClient.v2.Banner onlineAds = new DCC.OpenXClient.v2.Banner();
    onlineAds.imageUrl =@”D:\Pics\fantasy\fantasy1.jpg” ;
    DCC.OpenXClient.v2.Image[] img= new DCC.OpenXClient.v2.Image[1];
    img[0].content=”sdsd”;
    img[0].filename=@”D:\Pics\fantasy\fantasy1.jpg”;
    onlineAds.aImage =img ;
    int bnr = ox.AddBanner(onlineAds);

  17. Wavatar

    Indrani  |  May 10th, 2010 at 11:15 am #

    always getting the error “Image file name empty”;

    Where am I going wrong ?

    Thanks & Regards,

    Indrani

  18. Wavatar

    WC  |  September 14th, 2010 at 7:05 pm #

    Why does the url has to be localhost, like http://localhost/OpenX/www/api/v2/xmlrpc/ ?

    Can’t it be some thing liek http://myopensite.com/OpenX/www/api/v2/xmlrpc/ ?

  19. Wavatar

    Roger  |  September 14th, 2010 at 7:15 pm #

    @WC, indeed it can be any url you have OpenX installed. Localhost was just being used for example.

  20. Wavatar

    guste  |  October 26th, 2010 at 9:13 am #

    @Roger, I just try to add Web reference to my .Net project and I have an error message when I set “myopenXurl/www/api/v2/xmlrpc/” :

    faultCode
    105

    faultString
    XML error: Invalid document end at line 1

    How do you activate web service API. Is it during installation or is it in a configuration file? I thought it was activated by default?
    Thanks

  21. Wavatar

    guste  |  October 26th, 2010 at 10:04 am #

    OK, forget my previous post. I test using directly your source code and it works fine 😉 So it’s impossible to use standard .Net Web Service reference? We must use xmlrpc?

  22. Wavatar

    Roger  |  October 26th, 2010 at 1:52 pm #

    Glad you got it figured out Guste! You’re correct, OpenX only uses XML-RPC not SOAP which would be required to make a web reference.

  23. Wavatar

    guste  |  January 27th, 2011 at 5:26 pm #

    @Roger, I’m back with new issues. I devellop a .Net Back Office using OpenX API. I can Add Advertisers, Campaigns and Banners. I can also get Campaigns by advertiser, but I have an error when I try to get Banners with GetBannerListByCampaign() method:
    “response contains struct member aImage with missing value [response : array mapped to type Banner[] : element 0 : struct mapped to type Banner]”

    Or with GetBanner() method:
    “response contains struct member aImage with missing value [response : array mapped to type Banner[] : element 0 : struct mapped to type Banner]”

    What is strange is that creation of Banner works fine but after I can’t get it. I even try to set an aImage struct even if I don’t need it, but error still occured.
    Thanks

  24. Wavatar

    Roger  |  January 27th, 2011 at 8:36 pm #

    Hi Guste,

    I’ve got another OpenX hack to work around this problem.

    You need to change a single line in your OpenX install.

    In www/api/v2/common/XmlRpcUtils.php on Line 340,

    replace:

    return $variable;

    with

    return new XML_RPC_Value($variable, $GLOBALS[‘XML_RPC_Array’]);

    From my testing, the OpenX API wasn’t returning anything there for a local image ad (aImage), I’m not sure if that’s another bug or what. This change will just make sure the XML response is acceptable for XML-RPC.NET to handle.

  25. Wavatar

    guste  |  January 28th, 2011 at 7:55 am #

    On my side I made your modification on line 359 (switch […] case ‘custom’). If I well understand we could couple case ‘array’ and case ‘custom’? I don’t really understand what it really does but now it works when I call GetBannerListByCampaign() and GetBanner()
    Thanks a lot.

  26. Wavatar

    guste  |  January 28th, 2011 at 8:42 am #

    Sorry, I’ve got two other questions for you Roger. I see nothing in API which could permit to:
    1-Create, get and modify banner distribution options (distribution is the French term, I don’t know how to translate in English -> second tab when you are in banner detail screen in OpenX Back Office)?
    2-Access statistics?
    Thanks

  27. Wavatar

    Roger  |  January 28th, 2011 at 2:31 pm #

    Okay, glad that worked. You’re right, you could couple the array and custom cases together. It just depends on the version of OpenX, the array case didn’t exist in some previous versions.

  28. Wavatar

    Roger  |  January 28th, 2011 at 2:35 pm #

    – In my English version, the 2nd tab is “Delivery Options” for setting access filters on the banner. Is this what you’re looking for? (delivery limitations, visitor capping, etc)
    – There are approximately 40 statistic methods that need to be implemented. The source code is available if you feel comfortable to implement those yourself. Or if you let me know the ones you need specifically, I can get started on this for you.

  29. Wavatar

    guste  |  January 28th, 2011 at 3:18 pm #

    1-Yes, what I need is to create, get, and modify banner delivery options. Specially to manage several “Site Variables” (with AND condition) matching regex.
    2-I’ll contact you by mail to not pollute your blog.

  30. Wavatar

    Dennis  |  February 4th, 2011 at 2:29 pm #

    I am having difficulty performing a login. I am getting an error that states the following.

    “Response from server does not contain valid XML.” Any idea what might be causing this. Here is my login code.

    OpenXApiV2 OpenXAPI = new OpenXApiV2(edtURL.Text.Trim(), edtUserID.Text.Trim(), edtPassword.Text.Trim());

    OpenXAPI.Logon();

    Thank you for any help you may offer.

  31. Wavatar

    Roger  |  February 4th, 2011 at 2:37 pm #

    Hi Dennis, are you using the full OpenX API URL? Like: http://www.yoursite.com/OpenX/www/api/v2/xmlrpc/

  32. Wavatar

    Dennis  |  February 4th, 2011 at 2:50 pm #

    Here is the exact line I am using.

    string myURL = “http://www.msnapaccess.com/OpenX/www/api/v2/xmlrpc/”;

  33. Wavatar

    howard  |  November 17th, 2011 at 3:16 pm #

    Hi Roger,

    First, thanks for a great library. I’m having problems creating banners. The banner gets created, but the properties don’t get filled in right. The name, height, width, and Destination URL get the right values, but Image URL doesn’t get populated! I’m under a short deadline to get this working. Any ideas would really be helpful!

    Howard

    My code looks like:
    Banner banner = new Banner();
    banner.campaignId = Convert.ToInt32(txtCampaignId.Text);
    banner.bannerName = string.Format(“Test-{0}”, Guid.NewGuid().ToString());
    banner.storageType = “url”;
    banner.imageUrl = txtImageURL.Text; // I’ve tried both valid and invalid urls here
    banner.width = 300;
    banner.height = 100;
    banner.url = txtURL.Text; // I’ve tried both valid and invalid urls here

    api.Logon();
    bannerID = api.AddBanner(banner);
    api.Logoff();

  34. Wavatar

    Roger  |  November 22nd, 2011 at 3:32 pm #

    Hi Howard,
    It turns out the OpenX API itself doesn’t implement a way to handle the “URL” storage type.

    In my apps I’ve used the “html” storage type and specificed an htmlTemplate that includes the markup for an image.

    Hopefully that helps.

  35. Wavatar

    Jack  |  December 12th, 2011 at 6:44 pm #

    Hi Roger,

    I am using the following code to coonect to openx server:
    OpenXApiV2 openxapi = new OpenXApiV2(“http://www.myserver.com/OpenX/www/api/v2/xmlrpc/”,”username”, “password”);
    openxapi.Logon();

    As a result I get an error msg : “Response from server does not contain valid XML. ‘–‘ is an unexpected token. The expected token is ‘>’. Line 31, position 3.”
    This error is because as a response I get http://www.myserver.com/www/admin/index.php page. (I can see it using Fiddler)
    I wonder if my openx server setttings are wrong or it could be something else? Could you suggest possible solution please?
    Thank you

  36. Wavatar

    Priyanka  |  March 23rd, 2012 at 11:53 am #

    Hi,
    While adding Publisher I want to add oac_country_code ,oac_language_id also . My other attributes are getting added but not these 2 . My code is:-
    ‘oac_country_code’ => new XML_RPC_VALUE($objPublisher->oac_country_code,’string’) ,
    ‘oac_language_id’ => new XML_RPC_VALUE($objPublisher->oac_language_id,’int’),

    I added values:
    $objPublisher->oac_country_code = ‘es’;
    $objPublisher->oac_language_id = 2;
    Please some one let me know.

  37. Wavatar

    S Taylor  |  April 12th, 2012 at 12:51 am #

    Hi Butch,
    Nice work here. Just wanted to ask, do you have any idea how to remove banner limitations via the API after you’ve set them? We seem to be having an issue with that. i.e. If you previously set some limitations (geography, time etc) and then changed your mind or wanted to alter them or remove them altogether.

  38. Wavatar

    Jeet  |  June 15th, 2012 at 7:25 am #

    Hi Roger,

    I am writting one Codeigniter plugin for Openx API.

    My problem is i get the error back ” User must be OA installation admin” if user is not root. I want all the openx User should be able to login by using the plugin. Suppose we have 4 user as below

    1) admin 2) dev 3) pat 4) kelly

    Now,, my plugin works fine with user “admin”, but how i can make my plugin workable for rest 3 users. Please advice and appreciated if you can reply ASAP.

    I need logic, further i can implement.

    Thanks,
    jeet

  39. Wavatar

    Maddy  |  October 13th, 2012 at 6:32 am #

    Twitpic response object saying that invalid Username & Password,,,i have given the username & password which i use to login,,,dont knw where m doing Wrong
    Please Help me,,,
    Thanks in advance