Search code examples
node.jsbotframeworkazure-ad-graph-api

Node JS microsoft-graph-client return empty array


I use MS Bot Framework with MS Graph.. I need to get the data from the Sharepoint list. I use this code:

    async getMe() {
    return await this.graphClient
        .api('/sites/site.sharepoint.com/sites/site.sharepoint.com,9a51e995-62f9-4b40-81c2-d167c4c79182,2646bdf6-214f-482c-826f-c5e21676a79c/lists/84885DBF-980E-4AD2-8377-AAB746E6D41A/items')
        .version('beta')
        .expand('fields')
        .get().then((res) => {
            return res;
        });
}

This code return empty array:

{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#sites('site.sharepoint.com')/sites('site.sharepoint.com%2C9a51e995-62f9-4b40-81c2-d167c4c79182%2C2646bdf6-214f-482c-826f-c5e21676a79c')/lists('84885DBF-980E-4AD2-8377-AAB746E6D41A')/items","value":[]}

If I use graph explorer with this params it works fine...

graph client examples - https://github.com/microsoftgraph/msgraph-sdk-javascript


Solution

  • Change your .api() to read like this: https://graph.microsoft.com/beta/sites/{site}.sharepoint.com:/teams/{sitename}:/lists

    In changing the .api() value to the above example, I was able to successfully access a SharePoint list via MS Graph. Please note the ":" (colon) placed before each forward slash. It is a necessary component.

    Hope of help! Steve.