Office Scripts allows limited external API call support as documented on the official website.
Few things to note:
- There is no way to sign-in or use OAuth2 type of authentication flows. All keys/credentials have to be hardcoded (or read from another source).
- There is no infrastructure to store API credentials / keys. This will have to be managed by the user.
- External calls may result in sensitive data being exposed to undesirable endpoints or external data to be brought into internal workbooks. Your admin can establish firewall protection against such calls. Be sure sure to check with local policies prior to relying on external calls.
- If a script uses an API call, it will not function in Power Automate scenario. You'll have to use Power Automates HTTP action or equivalent actions to pull or push data from/to external service.
- External API call involves asynchronous API syntax and requires slighly advanced knowledge of the way async communication works.
- Be sure to check the data throughput prior to taking dependency. For instance pulling down entire external data-set may not be best option and instead pagination should be used to get data in chunks.
- REST API - most likely way you'll use the API call.
- Knowing how
async
await
works. - Knowing how
fetch
works.
- Mark you
main
function as an asynchronous function by addingasync
prefix.async function main(workbook: ExcelScript.Workbook)
... - Which type of API call are you making?
GET
,POST
,PUT
,DELETE
,PATCH
? Refer to REST API material to understand. - Obtain the service API endpoint, authentication requirements, headers, etc.
- Define the input or output
interface
to help with code completion and development time verification. See video for details. - Code/test/optimize. You can separte your API call routine to a separte function to make it re-usable from other part of script or for code-reuse from a different script (copy paste becomes much easier this way).
- Get repos Github API reference
- API call output: Go to browser or any HTTP interface and type in: https://api.github.com/users/{USERNAME}/repos by replacing {USERNAME} with your Github ID.
- Information fetched: repo.name, repo.size, repo.owner.id, repo.license?.name