0

I am using Office 365 to post an event in user calendar. I have a problem with the format of my post.

Here is my code (using Codeigniter and Rest lib) :

    $config = array (
        'server'            => 'https://outlook.office365.com/api/v1.0/me', 
        'http_user'         => 'mail@domain.com',
        'http_pass'         => 'mypassword',
        'http_auth'         => 'basic',
    );
    $this->load->library('rest', $config);

    $event = array(
        'Subject' => 'Try to post :(',
        'Body'    => array(
            'ContentType' => 'HTML',
            'Content'     => 'Not really concluant...'),
         'Start'    => "2015-04-22T18:00:00Z",   
         'End'      => "2015-04-22T19:00:00Z",   
         'StartTimeZone'    => 'Europe Standard Time',
         'EndTimeZone'  =>  'Europe Standard Time',
    );

    var_dump($this->rest->post('events', json_encode($event), 'json'));

And here is the response :

A supported MIME type could not be found that matches the content type of the response. None of the supported type(s) 'application/json;odata.metadata=minimal

What I am doing wrong ? Don't say all please !

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
Vincent Decaux
  • 9,857
  • 6
  • 56
  • 84

3 Answers3

0

I am not sure "Europe Standard Time" is correct. Please specify a time zone from the list displayed here in "Time Zone" column.

Venkat Ayyadevara - MSFT
  • 2,850
  • 1
  • 14
  • 11
0

You need to set the Content-Type header to application/json. I'm not sure how to do that with that particular API, but that sounds like your problem.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
0

I was looking for the same kind of solution, then I found :

You need first a user which has "owner" right to the calendar you want to create (you can test with your admin account) Then you need to encode in base64 your login passord GO to this site, you can do it online http://www.tools4noobs.com/online_php_functions/base64_encode/

then choose "base64encode" write inside the box like this example : john.smith@domain.com:password

Copy the result : example am9obi5zbWl0aEBkb21haW4uY29tOnBhc3N3b3Jk

1 step : read events (in php) :

<?
$mail = "eric.blik@domain.com"; // agenda email you want to check
    $opts = array(
      'http'=>array(
        'method'=>"GET",
        'header'=>"Authorization: Basic am9obi5zbWl0aEBkb21haW4uY29tOnBhc3N3b3Jk"
    // replace after basic by the password  
      )
    );
    $context = stream_context_create($opts);

    $ret_event = file_get_contents("https://outlook.office365.com/api/v1.0/users/" . $mail . "/calendarview?startDateTime=2015-06-30T09:00:00Z&endDateTime=2015-06-30T18:00:00Z", false, $context);
echo "<pre>"; 
print_r(json_decode($ret_event));
echo "</pre>"; 
?>

2nd step : write event (in php) :

<?
$mail = "eric.blik@domain.com"; // agenda email you want ot add event
    $url = "https://outlook.office365.com/api/v1.0/users/" . $mail . "/events";

    $fuseau = date("P"); 
        $titre = "Hello"; // Title
        $description = "Welcome to our world"; // Content can be html
        // Time zone is for France, check yours
        // Change the date time for your event
        $data_json = '{   "Subject": "' . $titre . '",
                          "Body": {
                            "ContentType": "HTML",
                            "Content": "' . $description . '"
                          },
                          "Start": "2015-07-07T18:00:00' . $fuseau . '",
                          "StartTimeZone": "Romance Standard Time",
                          "End": "2015-07-07T19:00:00' . $fuseau . '",
                          "EndTimeZone": "Romance Standard Time",
                          "Attendees": [
                            {
                              "EmailAddress": {
                                "Address": "' . $mail . '",
                                "Name": "TEST"
                              },
                              "Type": "Required"
                            }
                          ]
                        }';


        $options = array("http" => array(   "method" => "POST",
                                            "header" => "Authorization: Basic am9obi5zbWl0aEBkb21haW4uY29tOnBhc3N3b3Jk\r\n" .
                                                        "Content-type: application/json\r\n",
                                            "content" => $data_json                                         
                                            ));
        $context = stream_context_create($options);
        $retour_create_event = file_get_contents($url, false, $context);
        echo "<pre>";
        print_r(json_decode($retour_create_event));
        echo "</pre>";

        $id = json_decode($retour_create_event)->Id;
        echo "Id of the event : " . $id;
?>

Now check your agenda, you will have your event You can add a lot a settings, like categories or other information

It works as well for email, Onenote, and Sharepoint.

Waiting for your feed back