Skip to content

Instantly share code, notes, and snippets.

@ypcode
Last active October 22, 2017 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ypcode/9641e38a570773dc576e1a3160b33d9d to your computer and use it in GitHub Desktop.
Save ypcode/9641e38a570773dc576e1a3160b33d9d to your computer and use it in GitHub Desktop.
// 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