0
votes

I am trying to patch a calendar event with the Microsoft Graph API (from a Node express app).

  1. I create a new event with client.api('/me/events').post(myEvent) and it works just fine (I see it appear in my calendar). The return value has an ID which is:

AAMkADc0Yjg2ODdmLTlkNDQtNGQ0Yi1iNjBmLTE1MDdmYzI4MGJkOABGAAAAAADt0ZJy6xMCRq23C8icFGeqBwAOM3XMH4d2SYMQ5psbvFytAAAAAAENAAAOM3XMH4d2SYMQ5psbvFytAAJ_B-B7AAA=

  1. I then use client.api('/search/query').post(myQuery) to find the event based on some criteria, and this works fine. I receive an array of hits, with only one hit (which actually is the freshly created event, looking at the subject and body), and with a hitId equal to:

AAMkADc0Yjg2ODdmLTlkNDQtNGQ0Yi1iNjBmLTE1MDdmYzI4MGJkOABGAAAAAADt0ZJy6xMCRq23C8icFGeqBwAOM3XMH4d2SYMQ5psbvFytAAAAAAENAAAOM3XMH4d2SYMQ5psbvFytAAJ+B/B7AAA=

For some reason I don't understand why the 2 IDs are not fully identical: the _ is changed to +and -changed to /.

  1. I now want to modify the event, and try to update it with
let newVal = hits[0].resource // hits is coming from the result returned by the search query
newVal.id = hits[0].hitId // needed because the 'resource' does not contain the id
client.api('/me/events/'+hitId).patch(newVal)

But I get an error: Resource not found for the segment 'B7AAA='.

Could you please tell me how to make the patch work (and explain why the ID from the search is not strictly like the one created). I have read several examples in the documentation (such as https://docs.microsoft.com/en-us/graph/search-concept-events) but I could not find a solution.

Many thanks!

1
Have you tried the create event and the search events apis on Graph Explorer and seen the same behaviour with ID?Danstan

1 Answers

1
votes

So what is happening here is, PATCH /me/events/{hitId} is being resolved by Graph API such that the forward slash in the hitId denotes a path and Graph ends up using B7AAA= as a resource id hence the error Resource not found for the segment 'B7AAA='.

A work around that might work is to replace / in hitId(s) with %252F. You can do it like this.

client.api(`/me/events/${hitId.replace('/', '%252F')}`).patch(patch)

There is already this Issue on GitHub for documentation on how to handled these base64 encoded resource ids with /

As for the two IDs being non identical, Graph API will accept both of them and resolve to the same resource. I have no idea why they are different though.