[I am trying to fetch my email messages through Graph API into the webpart in sharepoint framework]
In the webpart Not getting the details of my emails through Graph API
Error : Cannot read property of 'value' of null
This property of 'value' is defined in the function "this._renderEmailList(messages.value)"
private _renderEmailList(messages: MicrosoftGraph.Message[]): void {
let html: string = '';
for (let index = 0; index < messages.length; index++) {
html += `<p class="${styles.description}">Email ${index + 1} - ${escape(messages[index].subject)}</p>`;
}
// Add the emails to the placeholder
const listContainer: Element = this.domElement.querySelector('#spListContainer');
listContainer.innerHTML = html;
}
I have call that function in the render function
public render(): void {
this.context.msGraphClientFactory
.getClient()
.then((client: MSGraphClient): void => {
// get information about the current user from the Microsoft Graph
client
.api('/me/messages')
.top(5)
.orderby("receivedDateTime desc")
.get((error, messages: any, rawResponse?: any) => {
this.domElement.innerHTML = `
<div class="${ styles.myFirstGraphWebPart}">
<div class="${ styles.container}">
<div class="${ styles.row}">
<div class="${ styles.column}">
<span class="${ styles.title}">Welcome to SharePoint!</span>
<p class="${ styles.subTitle}">Use Microsoft Graph in SharePoint Framework.</p>
<div id="spListContainer" />
</div>
</div>
</div>
</div>`;
// List the latest emails based on what we got from the Graph
this._renderEmailList(messages.value);
});
});
}