Beginner API Requests For File link Generation

SimonT 0 Reputation points
2023-01-26T11:01:32.3333333+00:00

Hi,

Apologies if this is a very simple question, I have just started using the graphAPI and I'm trying to read through the documentation for this. However, i think I am missing a few things that are stopping me from getting to where I want to be.

My end goal is to be able to call the API for specific files in my on drive and pull the sharing link from its response. In order to do this i need to get the correct authentification keys (?) in order to talk to the API in the first place

Any help that you guys can offer would be much appreciated !

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,028 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2023-01-26T13:11:13.2733333+00:00

    Hi SimonT,

    Thanks for reaching out!

    To do operations like getting specific files on users OneDrive.

    I suggest looking into the Graph API as follows:

    Get information about the user's drive:

    GET https://graph.microsoft.com/v1.0/me/drive

    Get the root folder of the drive:

    GET https://graph.microsoft.com/v1.0/me/drive/root

    To see the files that are in the folder:

    GET https://graph.microsoft.com/v1.0/me/drive/root/children

    To download a file by ID:

    GET https://graph.microsoft.com/v1.0/me/drive/items/{item-id}/content

    To share files from MS OneDrive to a user via MS graph API. And user can view user shared file directly through the link, you can create sharing Link for a DriveItem by consenting to the necessary permissions-Files.ReadWrite.All, Sites.ReadWrite.All

    Reference document: https://learn.microsoft.com/en-us/graph/api/driveitem-createlink?view=graph-rest-1.0&tabs=http

    Hope this helps.

    If the reply is helpful, please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment".

    0 comments No comments

  2. Zehui Yao_MSFT 5,871 Reputation points
    2023-01-30T07:28:46.97+00:00

    Hi SimonT, not sure if your problem is solved, indeed using the Graph API requires a token with the correct permissions. This is an explanation from the official documentation:

    https://learn.microsoft.com/en-us/graph/auth-v2-user?context=graph%2Fapi%2F1.0&view=graph-rest-1.0

    https://learn.microsoft.com/en-us/graph/auth-v2-service?view=graph-rest-1.0

    If you have any difficulty getting a token, please feel free to leave a message below.

    Best Wishes.


    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.

    0 comments No comments

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.