Last active
October 22, 2017 16:08
-
-
Save ypcode/9641e38a570773dc576e1a3160b33d9d to your computer and use it in GitHub Desktop.
This file contains 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
// Get the API key from tenant properties | |
this.context.spHttpClient | |
.get(`_api/web/GetStorageEntity('${this.properties.apiKeyPropertyKey}')`, SPHttpClient.configurations.v1) | |
.then((tenantPropResponse: Response) => tenantPropResponse.json()) | |
.then((prop) => { | |
let userDisplayName = this.context.pageContext.user.displayName; | |
return this.context.httpClient.get(`${API_URL}?&name=${userDisplayName}&code=${prop.Value}`, | |
HttpClient.configurations.v1); | |
}) | |
.then((apiResponse: Response) => apiResponse.json()) | |
.then((apiPayload) => { | |
if (apiPayload.statusCode && apiPayload.statusCode != 200) { | |
Dialog.alert(`ERROR [${apiPayload.statusCode}] : ${apiPayload.error}`); | |
} else { | |
Dialog.alert(apiPayload.message); | |
} | |
}) | |
.catch(error => { | |
Dialog.alert("ERROR: UNAUTHORIZED ACCESS"); | |
console.log(error); | |
}); | |
return Promise.resolve(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment