Skip to content

Latest commit

 

History

History

API Calls

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

External API calls from Office Scripts

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.

Prior knowledge/useful resources

Steps

  1. Mark you main function as an asynchronous function by adding async prefix. async function main(workbook: ExcelScript.Workbook)...
  2. Which type of API call are you making? GET, POST, PUT, DELETE, PATCH? Refer to REST API material to understand.
  3. Obtain the service API endpoint, authentication requirements, headers, etc.
  4. Define the input or output interface to help with code completion and development time verification. See video for details.
  5. 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).

Scenario

Get repos info

Resources used in the demo

  1. Get repos Github API reference
  2. 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.
  3. Information fetched: repo.name, repo.size, repo.owner.id, repo.license?.name

Script used

Video

API Call video