Search code examples
azuremicrosoft-graph-apionedrive

Create folder on OneDrive with API


I am trying to create new folder on OneDrive through API, but I am getting Exception

Fatal error: Uncaught exception 'League\OAuth2\Client\Provider\Exception\IdentityProviderException' with message 'Must provide one of the following facets to create an item: Bundle, File, Folder, RemoteItem

This is with $a = ["name" => "Folder"];.

If I change it to this:

$a = ["name" => "Folder", "folder" => array()];
$this->provider->post('https://graph.microsoft.com/v1.0/me/drive/root/children',$a,$_SESSION['access_token']);

Then I get

Property folder in payload has a value that does not match schema

From the example page I am assuming that folder value should be empty array.


Solution

  • Correct format for the folder was $folderParameters = ["name" => $folderName, "folder" => ["childCount" => '0']];