5

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": "my-other-email@gmail.com",
                "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": "my_hotmail_email@hotmail.com"
            }
        }
    ],
    "organizer": {
        "emailAddress": {
            "name": "My Name",
            "address": "my_hotmail_email@hotmail.com"
        }
    }
}

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

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
codeinprogress
  • 3,193
  • 7
  • 43
  • 69
  • 2
    Are these accounts linked? If so then it is simply replacing your `@gmail` with the "primary" `@hotmail` address. – Marc LaFleur May 02 '19 at 14:48
  • 1
    I didn't understand what you mean by linked? I am creating the outlook event by signing in with my hotmail account and the event attendees could be anyone (I have given my own gmail for testing). – codeinprogress May 02 '19 at 15:51
  • 1
    If you go to [Outlook.com](https://outlook.com), can you login to your Hotmail account using your Gmail address? If so then Outlook sees your `@gmail` address as an alias and swaps it for the primary address. – Marc LaFleur May 02 '19 at 16:25
  • 2
    Yes you were absolutely right. My gmail was linked to my hotmail account. I used another email and it worked like a charm. Thanks for the help. – codeinprogress May 03 '19 at 05:21

1 Answers1

2

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.

Marc LaFleur
  • 31,987
  • 4
  • 37
  • 63
  • This answer saved my hair being ripped out! I couldnt figure out why it was silently dropping some email addresses and not others. Thanks! – cowley05 Jan 12 '23 at 12:06