Using On-premise SharePoint REST API to retrieve documents with client secret credentials

Jasper Baetslé 120 Reputation points
2023-10-13T15:08:39.3466667+00:00

Hi, I am trying to make an application where I can read the contents of a file that resides on the on-premise SharePoint. I have multiple points where I am failing to do this.

Authentication

I can use the api in my web browser by using GET requests and authenticating with my own username / password / 2fa, but I cannot find any place in the documentation about how to use client-id and client-secrets that I have already generated.

API

The API itself seems to be returning only properties of the file and not the file contents itself. Is this functionality of retreiving the full file possible?

Library / API v

Which API version or library is recommended for this? Should I use the CSOM library in any way? I read on https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard that on-premise is supported in .net framework and not .net core, how do I check the sharepoint type?

Whenever I try to surf to http://server/site/_api/ I get the AD login page where I need to login with username/password/2fa, so maybe the on-prem is connected online thus being able to use the SharepointOnlineCredentials?

Any help appreciated

Kind regards

Jasper

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-10-16T06:23:09.6933333+00:00

    Hi @Jasper Baetslé

    Do you want SharePoint On-premise information available as an application?

    It is recommended that you use SharePoint App-Only

    SharePoint App-Only is the older, but still very relevant, model of setting up app-principals. This model works for both SharePoint Online and SharePoint on-premises (2013/2016/2019/subscription edition) and is ideal to prepare your applications for migration from SharePoint on-premises to SharePoint Online.

    Here is how to register for this app

    https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs

    Regarding sharepoint api, there are currently two types: one is sharepoint rest api and the other is Graph api.

    There is a difference between the two.

    The Graph API and the SharePoint REST API are two different ways of accessing data from SharePoint and other Microsoft 365 services. The main difference is that the Graph API is a more general and unified API that can access data from various Microsoft 365 services, while the SharePoint REST API is designed to work specifically with SharePoint sites and content. Here are some of the advantages and disadvantages of each API:

    Graph API :https://learn.microsoft.com/en-us/graph/use-the-api

    Advantages:

    Provides a consistent developer experience for authentication, documentation, SDKs, samples and features like change notifications, delta queries and batch requests.

    Supports identity-based access, which means you can use the same URL to access different resources based on the user’s permissions.

    Covers most of the common scenarios for working with SharePoint sites, lists, folders, items and documents.

    Disadvantages:

    Does not support some of the SharePoint-specific features,

    May have some latency or performance issues compared to the SharePoint REST API, since it is a proxy to the actual SharePoint API.

    SharePoint REST API:https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-rest-endpoints

    Advantages:

    Provides more functionality and control over SharePoint-specific features, such as site settings, site templates, workflows, search, etc.

    May have better performance and responsiveness than the Graph API, since it directly accesses the SharePoint data source.

    Disadvantages:

    Requires different endpoints and authentication methods for different Microsoft 365 services, which can increase the complexity and maintenance of the app.

    Uses function-based access, which means you need to know the exact name and parameters of the function to access a resource.

    Depending on your needs and preferences, you can choose either the Graph API or the SharePoint REST API to interact with SharePoint. However, Microsoft recommends using the Graph API as much as possible, since it is the future direction of Microsoft 365 integration.

    I hope this helps you with your project. If you have any other questions, please let me know.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.

    Best Regards

    Cheng Feng


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.