MS graph API sharepoint site. Create a folder in r

2020-04-20 11:47发布

问题:

I try to use the MS graph API to work with sharepoint sites. All works fine, except i can not find how to create a folder in root of a site (folders are documents library).

If i know the site id (SITEID) i can list folders in root of the site as drives

GET /v1.0/sites/SITEID/drives

I have ID for each item (it is like a drive ID). The i can list folders on drives (which are subfolders of top level folders on a site)

GET /v1.0/sites/SITEID/drives/DRIVEID/root/children

I can create folders in this place and subfolders

POST /v1.0/sites/SITEID/drives/DRIVEID/root/children
{
  "name": "New Folder 2",
  "folder": {}
}

But how to create a top level folder on a site? In fact, how to create new drive on a site?

I try to guess something like

POST /v1.0/sites/SITEID/drives
{
  "name": "New Drive",
  "folder": {}
}

But this doesn't work

Also, i tried to create a list https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/list_create

POST /v1.0/sites/SITEID/lists
{
  "name": "Books",
  "columns": [
    {
      "name": "Author",
      "text": { }
    },
    {
      "name": "PageCount",
      "number": { }
    }
  ],
  "list": {
    "template": "documentLibrary"
  }
}

no success

回答1:

I think you are wrong. Folders are not document libraries.

Drive is a document library. Document library is a list with template: document library, so drive is also a list.

Endpoint

GET /v1.0/sites/SITEID/drives

will return a list of lists with template: document library.

Endpoint

GET /v1.0/sites/SITEID/lists

will return all lists of all types.

To create new drive (a document library) you should create a new list with document library as template. Then you will have a new drive in a root of the site.

What problem do you have with creation of a new list?