Re-displaying the Consent Dialog in Graph Explorer
I was trying to follow along with Richard diZerega’s excellent tutorial on using the Excel REST Api in the Microsoft Graph (Episode 28 of the Office Dev Show). As he demonstrated, I was using the Graph Explorer and was able to find my workbook by GETting
https://graph.microsoft.com/beta/me/drive/root/children?$select=name,id
And then get a reference to the workbook I wanted to use by GETting
https://graph.microsoft.com/beta/me/drive/items/[the id I found]/workbook
I could even find out what was in cells A1:C1 on Sheet1 of the workbook by GETting
https://graph.microsoft.com/beta/me/drive/items/[the id I found]/workbook/worksheets('Sheet1')/range(address='Sheet1!A1:C1')
BUT, when I tried to set the values in that range by PATCHing
https://graph.microsoft.com/beta/me/drive/items/[the id I found]/workbook/worksheets('Sheet1')/range(address='Sheet1!A1:C1')
and passing
{ "values" : [["First Name","Last Name","Company"]] }
in the body, I got the following cryptic error:
{
"error": {
"code": "EditModeAccessDenied",
"message": "",
"innerError": {
"request-id": "6610f3fe-93d5-42b1-8687-0f53dce1e25c",
"date": "2016-05-24T05:36:04"
}
}
}
Which is pretty wierd, because I can quite happily edit the workbook in Excel online and even via other apps using the Graph.
It turns out that the problem was that I'd consented to the Graph Explorer application back in the days when it was a GET only interface, so I needed to pop up the common consent dialog again with the new permissions it needed for doing POST and PATCH (and DELETE)
Unfortunately, there didn't seem to be an easy way to do this (at least I couldn't find one). Then my mate Chad Brooks suggested that I needed to add the
promt=consent
parameter to the auth dialog page.
I re-launched the Graph Explorer and clicked the Sign In link. At the next page (the login page), I manually edited the URL to add the parameter and re-loaded. I logged in as normal and lo! I was presented with the common consent dialog. Now when I PATCH that range I get a much more sensible answer:
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#worksheet",
"@odata.type": "#microsoft.graph.range",
"@odata.id": "/users('516bd36d-a7e4-48b5-b6f7-f909133a9b8e')/drive/items('01BDIUI7YEHLXXPQG52ZBLRSWBSQX3DWEW')/workbook/worksheets(%27%7B00000000-0001-0000-0000-000000000000%7D%27)/range(address=%27Sheet1!A1:C1%27)",
"address": "Sheet1!A1:C1",
"addressLocal": "Sheet1!A1:C1",
"cellCount": 3,
"columnCount": 3,
"columnHidden": false,
"columnIndex": 0,
"formulas": [
[
"First Name",
"Last Name",
"Company"
]
],
"formulasLocal": [
[
"First Name",
"Last Name",
"Company"
]
],
"formulasR1C1": [
[
"First Name",
"Last Name",
"Company"
]
],
"hidden": false,
"numberFormat": [
[
"General",
"General",
"General"
]
],
"rowCount": 1,
"rowHidden": false,
"rowIndex": 0,
"text": [
[
"First Name",
"Last Name",
"Company"
]
],
"values": [
[
"First Name",
"Last Name",
"Company"
]
],
"valueTypes": [
[
"String",
"String",
"String"
]
]
}
All's right with the world once more.