tags:

views:

53

answers:

2

I'm trying to insert a campaign into openX with the XML-RPC API, everything except the start and end dates is working fine, my current code looks like this:

$campaign = new XML_RPC_Value(
                    array('advertiserId' => new XML_RPC_Value($advertiserID, 'int'),
                            'campaignName' => new XML_RPC_Value('My Banner', 'string'),
                            'startDate' => new XML_RPC_Value(new Date(time()), 'DateTime'),
                            'endDate' => new XML_RPC_Value(new Date(time() + (3600*24*3), 'DateTime')/*3 days into the future*/,
                            'impressions' => new XML_RPC_Value(10000, 'int'),
                            'clicks' => new XML_RPC_Value(-1, 'int'),
                            'priority' => new XML_RPC_Value(1, 'int'),
                            'weight' => new XML_RPC_Value(0, 'int')
                    ), 
                    'struct');

I'm using the PEAR XML_RPC package. This code runs fine without generating any errors, however when I look at the OpenX control panel my new campaign does not have a start or end date (they are set to "Start Immediatly" and "Don't Expire").

What format does the date need to be in, for OpenX to accept it?

A: 

Have you read this? Changing date format It should be able to tell you how it is set up and then you can either enter it that way or change it to fit your needs.

Bactos
+1  A: 

EDIT: looked at the http://pear.php.net/package/XML_RPC code, you need to encode your dates as ISO 8601 strings yourself:

Try like this:

$campaign = new XML_RPC_Value(
                array('advertiserId' => new XML_RPC_Value($advertiserID, 'int'),
                        'campaignName' => new XML_RPC_Value('My Banner', 'string'),
                        'startDate' => new XML_RPC_Value(date('c'), 'dateTime.iso8601'),
                        'endDate' => new XML_RPC_Value(date('c', time() + (3600*24*3)), 'dateTime.iso8601')/*3 days into the future*/,
                        'impressions' => new XML_RPC_Value(10000, 'int'),
                        'clicks' => new XML_RPC_Value(-1, 'int'),
                        'priority' => new XML_RPC_Value(1, 'int'),
                        'weight' => new XML_RPC_Value(0, 'int')
                ), 
                'struct');

(The XML-RPC date type is 'dateTime.iso8601', not 'DateTime'.)

Walter Mundt
Works perfectly, thanks.
Unkwntech