Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attendees not added when creating an Outlook calendar event using Microsoft Graph API

I am creating an Outlook calendar event using Microsoft's Graph API with my Node.js application. Following this documentation/example link: https://learn.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/calendar-rest-operations#CreateEvents

My Code:

var options = {
    method: 'POST',
    url: 'https://graph.microsoft.com/v1.0/me/calendar/events',
    headers: {
        'Authorization': 'Bearer ' + access_token,
        'Content-Type': 'application/json'
    },
    body: {
        "subject": "Node.js outlook test",
        "body": {
            "contentType": "HTML",
            "content": "Test event created from node.js"
        },
        "start": {
            "dateTime": "2019-03-25T12:00:00",
            "timeZone": "Pacific Standard Time"
        },
        "end": {
            "dateTime": "2019-03-25T14:00:00",
            "timeZone": "Pacific Standard Time"
        },
        "isAllDay": false,
        "location": {
            "displayName": null
        },
        "attendees": [{
            "emailAddress": {
                "address": "[email protected]",
                "name": "Adele Vance"
            },
            "type": "required"
        }]
    },
    json: true
};

request(options, function (err, response, body) {
    if (err) throw new Error(err);
    res.send(body);
});

The event is created in the outlook calendar but there are no attendees associated with the event.

I get the following response back after the event is created

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('my_hotmail_email%40hotmail.com')/calendar/events/$entity",
    "@odata.etag": "W/\"69zWaBpmuEqq9NMFBSWV6QACU8X/gQ==\"",
    "id": "AQMkADAwATYwMAItYzA3My1mNzUxLTAwAi0wMAoARgAAAwh1Hv4SptVMlm3BaW7y4g0HAOvc1mgaZrhKqvTTBQUAJZXpAAACAQ0AAADr3NZoGma4Sqr00wUFACWV6QACU7Qp1gAAAA==",
    "createdDateTime": "2019-05-02T09:12:12.0349227Z",
    "lastModifiedDateTime": "2019-05-02T09:12:12.0789547Z",
    "changeKey": "69zWaBpmuEqq9NMFBSWV6QACU8X/gQ==",
    "categories": [],
    "originalStartTimeZone": "Pacific Standard Time",
    "originalEndTimeZone": "Pacific Standard Time",
    "iCalUId": "040000008200E00074C5B7101A82E0080000000077C77520C700D5010000000000000000100000001CB042E1D2C57341BA3D3799F9853B63",
    "reminderMinutesBeforeStart": 15,
    "isReminderOn": true,
    "hasAttachments": false,
    "subject": "Node.js outlook test",
    "bodyPreview": "Test event created from node.js",
    "importance": "normal",
    "sensitivity": "normal",
    "isAllDay": false,
    "isCancelled": false,
    "isOrganizer": true,
    "responseRequested": true,
    "seriesMasterId": null,
    "showAs": "busy",
    "type": "singleInstance",
    "webLink": "https://outlook.live.com/owa/?itemid=AQMkADAwATYwMAItYzA3My1mNzUxLTAwAi0wMAoARgAAAwh1Hv4SptVMlm3BaW7y4g0HAOvc1mgaZrhKqvTTBQUAJZXpAAACAQ0AAADr3NZoGma4Sqr00wUFACWV6QACU7Qp1gAAAA%3D%3D&exvsurl=1&path=/calendar/item",
    "onlineMeetingUrl": null,
    "recurrence": null,
    "responseStatus": {
        "response": "organizer",
        "time": "0001-01-01T00:00:00Z"
    },
    "body": {
        "contentType": "html",
        "content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nDoes mid month work for you?\r\n</body>\r\n</html>\r\n"
    },
    "start": {
        "dateTime": "2019-03-25T12:00:00.0000000",
        "timeZone": "Pacific Standard Time"
    },
    "end": {
        "dateTime": "2019-03-25T14:00:00.0000000",
        "timeZone": "Pacific Standard Time"
    },
    "attendees": [
        {
            "type": "required",
            "status": {
                "response": "none",
                "time": "0001-01-01T00:00:00Z"
            },
            "emailAddress": {
                "name": "My Name",
                "address": "[email protected]"
            }
        }
    ],
    "organizer": {
        "emailAddress": {
            "name": "My Name",
            "address": "[email protected]"
        }
    }
}

As you can see in the attendees array it gives my own hotmail/outlook account but not the gmail account which was included in the request.

I also do not get any calendar invite on my gmail account. Any idea what might be going wrong?

enter image description here

like image 874
codeinprogress Avatar asked Nov 06 '22 17:11

codeinprogress


1 Answers

The issue is that your Outlook/Hotmail account is aware of your GMail address. The easiest way to check if this is the case is to log in to Outlook.com using your @gmail.com address but your Outlook/Hotmail password. If your Microsoft Account has your GMail address listed as a valid alias it will authenticate you just as if you'd entered your primary address.

Since it sees your GMail address as an alias, Outlook is automatically swapping out the GMail alias for your "default" address (your @outlook.com address).

Try using a new GMail address and it should work as you expect.

like image 123
Marc LaFleur Avatar answered Nov 11 '22 17:11

Marc LaFleur