Created
August 27, 2020 15:27
-
-
Save brettwhitty/f70d6268da9807d50b0ecbfb2ab766cc to your computer and use it in GitHub Desktop.
Access the elio Atlas API to do various things from Excel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: AtlasAPI | |
| description: Access the elio Atlas API to do various things from Excel. | |
| host: EXCEL | |
| api_set: {} | |
| script: | |
| content: > | |
| /** | |
| * Gets an authentication token from the Atlas API | |
| * @customfunction | |
| * @param server Name of the elio server. | |
| * @param username Username to get a token for. | |
| * @param password Password for the authenticating user. | |
| * @param mode Mode of the user login. | |
| * @return an authorization token for accessing the Atlas API. | |
| */ | |
| async function getAuthToken(server = "", username = "", password = "", mode | |
| = "") { | |
| if (username == "" || server == "" || password == "" || mode == "") { | |
| return "BAD_PARAMS"; | |
| } | |
| const url = `https://${server}.ad.personalgenome.com/api/v1/api-auth-token/`; | |
| const myInit = { | |
| method: "POST", | |
| headers: { | |
| "Content-Type": "application/json" | |
| }, | |
| mode: "cors", | |
| cache: "default", | |
| body: JSON.stringify({ | |
| mode: mode, | |
| username: username, | |
| password: password | |
| }) | |
| }; | |
| const response = await fetch(url, myInit); | |
| //Expect that status code is in 200-299 range | |
| if (!response.ok) { | |
| console.log("Respone not OK!"); | |
| //throw new Error(response.statusText); | |
| return response.statusText; | |
| } else { | |
| console.log("Response is OK!"); | |
| const jsonResponse = await response.json(); | |
| console.log(JSON.stringify(jsonResponse)); | |
| return jsonResponse.token; | |
| } | |
| } | |
| language: typescript | |
| libraries: | | |
| https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
| @types/office-js | |
| core-js@2.4.1/client/core.min.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment