Skip to content

Instantly share code, notes, and snippets.

@AsishP
Created May 6, 2019 21:26
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 AsishP/5967008fec6481cf0aeeeebb3fb6dc77 to your computer and use it in GitHub Desktop.
Save AsishP/5967008fec6481cf0aeeeebb3fb6dc77 to your computer and use it in GitHub Desktop.
Get operation using SP Http Client
try {
let spHttpClient : SPHttpClient = context.spHttpClient;
let url = `${context.pageContext.web.absoluteUrl}/_api/web/lists/GetByTitle('${listTitle}')/Items?$select=Author/EMail,*&$expand=Author&$filter=Author/EMail eq 'XYZ@xyz.com'`;
spHttpClient.get(url, SPHttpClient.configurations.v1).then((response : SPHttpClientResponse) => {
if(response.ok)
{
response.json().then((responseJson : any) => {
console.log(responseJson);
if (this.isValidObject(responseJson) && responseJson.value.length !== 0) {
resolve({
associatedItem: responseJson.value[0]
});
} else {
resolve({
associatedItem: null
});
}
});
}
});
} catch (error) {
throw (error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment