'Can I call a custom function in an excel spreadsheet from the microsoft graph?
In the Microsoft graph REST API docs, it shows how to call a function from an excel sheet.
https://graph.microsoft.com/v1.0/me/drive/root:/book1.xlsx:/workbook/functions/pmt
content-type: Application/Json
authorization: Bearer {access-token}
workbook-session-id: {session-id}
{
"rate": 4.5,
"nper": 12,
"pv": -1250
}
The example they use is pmt
, which is a built in Excel function. It seems odd that the query needs to hit a specific excel file to do that, as the result from that function is totally independent from a specific workbook.
Is this a quirk of excel, that everything needs to hit a specific workbook, or is it possible to make this API hit a custom function?
I've tried to make a custom function in an .xlsm that's in my onedrive:
Function YO(name)
YO = "yo " + name
End Function
Which works in the spreadsheet, but gives the following error from the API:
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'yo'.",
"innerError": {
"date": "2022-05-13T07:58:00",
"request-id": "5ca7d80b-e326-4819-abf7-1928d08c599e",
"client-request-id": "ab896375-ce1f-9ee2-2b08-2fa7d378f007"
}
}
}
This leaves me with these questions:
- If this is possible, how would I do it?
- If it's not possible, why does it need a specific workbook to run the function?
The real world use case I can see for this is: If I want to expose a calc that's in a spreadsheet to an external user as an API that doesn't need a developer to build the logic for an endpoint in a fancy way.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|