0

I use the following code to make a new folder using the microsoft graph api:

    $tokenCache = new TokenCache();
    $accessToken = $tokenCache->getAccessToken();
    $graph = new Graph();
    $graph->setAccessToken($accessToken);

    $queryParams = array(
        'name' => 'nameOfnewFolder',
        'folder' => new \stdClass(),
        'microsoft.graph.conflictBehavior' => 'rename'
    );

    $url = '/me/drive/root/children?' . http_build_query($queryParams);

    return $this->graph->createRequest('POST', $url)
        ->setReturnType(Model\DriveItem::class)
        ->execute();

This returns the following error:

Empty Payload. JSON content expected.

What am I doing wrong here?

Mister Verleg
  • 4,053
  • 5
  • 43
  • 68

1 Answers1

0

Found the awnser:

One can add the json using:

->attachBody($queryParams)

as seen here:

 return $this->graph->createRequest('POST', $url)->addHeaders(array("Content-Type" => "application/json"))
                ->attachBody($queryParams)
                ->setReturnType(Model\DriveItem::class)
                ->execute();
Mister Verleg
  • 4,053
  • 5
  • 43
  • 68