Forum Discussion
consume sharepoint API from nodejs
I am writing a nodejs script that runs on linux to upload files to share point directory. The script runs every night without any user intervention. I have created both client id/secret in Azure Portal (gave Sites.ReadWrite.All permission) and in SharePoint (gave full control) as well tried to get token using the secrets to upload files. and getting token with the below request:
https://login.microsoftonline.com/{{directoryId}}/oauth2/v2.0/token
[{"key":"grant_type","value":"client_credentials","description":"","type":"text","enabled":true},{"key":"client_id","value":"{{azureApp_clientId}}","description":"","type":"text","enabled":true},{"key":"client_secret","value":"{{azureApp_clientSecret}}","description":"","type":"text","enabled":true},{"key":"scope","value":"https://graph.microsoft.com/.default","description":"","type":"text","enabled":true}]
And, then calling the graph API: https://graph.microsoft.com/v1.0/sites and getting the response:
Whether I should use Graph API or SharePoint Online Rest API? What I'm missing or is there a complete article to help me?
Any help would much appreciated.
Thank you
1 Reply
- nbaluniCopper Contributor
Microsoft Graph API:
Unified Endpoint: Microsoft Graph provides a unified endpoint to access data across various Microsoft 365 services (including SharePoint, Outlook, OneDrive, Teams, etc.).
Richer Functionality: It offers a broader range of functionalities and capabilities beyond SharePoint-specific operations. You can access not just SharePoint but other Microsoft 365 services using a single API.
Consistency and Future-Proofing: Microsoft is investing heavily in the Graph API, making it the recommended endpoint for accessing Microsoft 365 data. New features and improvements are more likely to be introduced in Microsoft Graph rather than in individual service-specific APIs.
Authentication: Graph API uses OAuth 2.0 for authentication, providing modern authentication methods.
SharePoint Online REST API:
Specific to SharePoint: The SharePoint REST API is tailored specifically for SharePoint functionalities, providing direct access to SharePoint lists, libraries, sites, etc.
Granular Control: It may offer more granular control or specific operations that are not available or not as straightforward in the Graph API.
Maturity and Documentation: SharePoint REST API has been around longer and might have more comprehensive documentation and examples for SharePoint-specific operations.
Factors for Decision:
Scope of Integration: If your application needs to interact extensively with various Microsoft 365 services beyond SharePoint, using Microsoft Graph might provide a more comprehensive solution.
Specific SharePoint Operations: For highly specific or complex SharePoint operations that are not available in Microsoft Graph, using SharePoint REST API could be more appropriate.
Future-Proofing: Considering Microsoft's focus on Microsoft Graph, if you're looking for a future-proof solution that aligns with Microsoft's direction, Graph API might be a better choice.
Ease of Use: If your primary focus is on SharePoint-specific tasks and the functionalities offered by the SharePoint REST API meet your requirements, it might be more straightforward to use.
In many cases, especially for modern applications aiming for a broader integration with Microsoft 365 services, using the Microsoft Graph API is recommended due to its comprehensive capabilities and the direction of Microsoft's development efforts. However, specific use cases and requirements may necessitate using the SharePoint Online REST API for its tailored functionalities.