Tiocrash
Tiocrash

Reputation: 357

Where to find the {parent-id} of a drive item?

I'm trying to upload a file into my organization's SharePoint using Microsoft Graph but I can't find {parent-id} for the following endpoint:

PUT /users/{user-id}/drive/items/{parent-id}:/{filename}:/content

Is the {parent-id} supposed to be the id of the parent directory that file will be inserted into?

Upvotes: 6

Views: 5929

Answers (1)

Marc LaFleur
Marc LaFleur

Reputation: 33094

That is correct. As an example, the following would upload a file named MyFile.txt into a folder named MyFolder in my account's OneDrive:

PUT /me/drive/root:/MyFolder/MyFile.txt:/content

The URI is broken down into the following components:

  • Drive Path (/me/drive/root) - This tells Graph which drive you want to address. The URI /me/drive/root address the root of your account's OneDrive. You could also address another user's drive using /users/{userPrincipalName}/drive/root or a SharePoint Site's default Document Library using /sites/{site-id}/drive/.

  • File Path (:/MyFolder/MyFile.txt:) - This tells Graph which file you want to address. If you want to put the file in the root of the Drive you could use :/MyFile.txt:. If you want to put it within a folder two levels deep you could use :/Folder1/Folder2/MyFile.txt.

  • File Content (/content) - This tells Graph that you want to address a file's content (i.e. the contents of MyFile.txt) rather than it's meta-data (i.e. the date MyFile.txt was created).

Upvotes: 4

Related Questions