none
Outlook REST API v2.0 batches RRS feed

  • Question

  • I've successfully used the Outlook REST API to clear my calendar and add events to it, but I'm trying to send batched API requests to Office 365 to lower the number of calls I need to make to the API. I've been going over the documentation for the last several days and keep getting "(400) Bad Request" responses. I know that this means my request needs to be changed, but I can't seem to be able to figure out what I'm doing wrong. I'm doing all this with Powershell's Invoke-RestMethod cmdlet, documented below. Any help would be appreciated.

    Powershell:

    Invoke-RestMethod "https://outlook.office.com/api/v2.0/users('$user_email_address')/`$batch" `
    					-Method Post `
    					-Headers @{"Authorization" = "Bearer $bearerToken"
    							   "Host" = "outlook.office.com"
    							   "Prefer" = "odata.continue-on-error"
    							   "x-AnchorMailbox" = "$user_email_address"} `
    					-ContentType "multipart/mixed; boundary=batch_$batch_id" `
    					-Body $POST_request
    $POST_request contents:
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-01 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-01 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-02 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-02 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-03 07:15:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-03 07:30:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-06 08:45:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-06 09:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-07 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-07 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-08 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-08 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-09 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-09 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-10 08:15:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-10 08:30:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-13 06:45:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-13 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-14 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-14 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-15 08:15:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-15 08:30:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-16 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-16 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-17 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-17 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-20 08:45:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-20 09:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-22 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-22 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-23 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-23 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-24 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-24 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-28 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-28 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-29 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-29 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42
    Content-Type: application/http 
    Content-Transfer-Encoding: binary 
    
    POST https://outlook.office.com/api/v2.0/users('<user>@<company>.com')/calendars/<calendar id>/events
    Content-Type: application/http
    
    {
               "Subject": "<Subject>",
               "IsReminderOn":"false",
               "Body": {
                 "ContentType": "HTML",
                 "Content": "<Content>"
               },
               "Start": {
                   "DateTime": "2017-11-30 06:55:00",
                   "TimeZone": "Pacific Standard Time"
               },
               "End": {
                   "DateTime": "2017-11-30 07:00:00",
                   "TimeZone": "Pacific Standard Time"
               }
             }
    
    
    --batch_af8b1720-f660-429e-bd14-97daf5523b42--
    
    

    Tuesday, November 14, 2017 4:44 PM