Creating an event via the salesforce php api

Credit goes to this url for this post. I repost in case his site goes down and the info is lost.
The object to update or insert a new calendar event is the "Event" object in salesforce

There are 4 required fields that need to be inserted in order for the event to be added to your instance of Salesforce.

Assigned To
Start (date and time)
End (date and time)

Those API field names are

Owner Id

Remember that Salesforce times are all set to GMT, so you have to account for that. Since my time is set to -6 GMT, I have to adjust my code for that:

PHP Code:


require_once ('./soapclient/SforcePartnerClient.php');
require_once ('./soapclient/SforceHeaderOptions.php');

$mystuff = array('OwnerId'          => '00550000000wI2LAAU', // Assigned To
                 'Subject'          => 'PHP Event Addidtion Test 2', //Subject
                 'StartDateTime'    => '2008-08-05T12:00:00.000Z', //Start time of event
                 'EndDateTime'      => '2008-08-05T13:00:00.000Z'); //End time of event **ALL TIMES ARE GMT, REMEMBER TO ACCOUNT FOR THIS****
//clean User to allow changing of characters to XML
$mystuff = array_map('htmlspecialchars',$mystuff);

//try to add User from from array
    //salesforce login and wsdl
    $wsdl = './soapclient/partner.wsdl.xml';
    $userName = ""; // change this to a valid email
    $password = "password"; // change this to a valid password

    //connect to salesforce
    $client = new SforcePartnerClient();
    $loginResult = $client->login($userName,$password);

    $sObject = new sObject();
    $sObject->type = 'Event';
    $sObject->fields = $mystuff;

    //this part adds the contact to salesforce
    $result = $client->create(array($sObject));

    if ($result->success)
        echo "A new Calendar event has been added to your instance of Salesforce with an Id of ".$result->id."
"; echo "**************** ALL DONE ****************
"; exit; } else { $errMessage = $result->errors->message; echo $errMessage; } } catch (exception $e) { // This is reached if there is a major problem in the data or with // the connection. Normal data errors are caught by // echo '

return false;