MS Team App to fetch SharePoint list item

Kevin Thankachan 41 Reputation points
2021-03-10T02:52:37.16+00:00

I'm following the below link to create a personal tab in a Team App.

https://learn.microsoft.com/en-us/microsoftteams/platform/build-your-first-app/build-personal-tab

I need to fetch and display contents from a SharePoint list here. I get the below error-

{"odata.error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform this action or access this resource."}}}

The user is a SharePoint Administrator and Site collection Admin.

Code-

var spUrl="https://****.sharepoint.com/sites/Project4thCOM2"; //hard coded SP Site URL  
var web = Web(spUrl);   

await web.lists.getByTitle("Teams List").items().then((items)=>{  
  items.forEach(element=>{  
      this.setState({  
        Title:element['Title'],  
        SingleLine:element['SingleLine']  
        })  
  })  
}).catch(err=>console.log(err))  

Could anyone please suggest how we can access the SharePoint list data here.
Regards,
Kevin

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,679 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,866 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-03-10T09:05:45.253+00:00

    You need to get the access token to request the API.
    Integrating SharePoint Data Into Node.JS With Access Token
    Or you may try to use Graph API.
    Tutorial:Calling Microsoft Graph from your Teams application


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful