23 Jul, 2009 in
Programming by
Roger
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.
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
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?
Indrani | April 6th, 2010 at 11:04 am #
Hi,
Thanks. It worked.
Regards,
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
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.
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
Roger | April 16th, 2010 at 8:35 pm #
Sorry Indrani, I should have specified, the LinkCampaign method is on the OpenXApiV2 class.
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
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,
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.
Indrani | April 22nd, 2010 at 6:40 am #
Hi,
Thanks it worked.
Regards,
Indrani
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
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
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
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!
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);
Indrani | May 10th, 2010 at 11:15 am #
always getting the error “Image file name empty”;
Where am I going wrong ?
Thanks & Regards,
Indrani
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/ ?
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.
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
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?
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.
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
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.
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.
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
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.
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.
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.
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.
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/
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/”;
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();
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.