From 27b956eb53a0d37f59ea1cc556624c93b95c9ab7 Mon Sep 17 00:00:00 2001 From: vgrem Date: Fri, 3 Mar 2023 20:58:23 +0200 Subject: [PATCH] OneDrive API: createFolder function fix --- src/OneDrive/DriveItems/DriveItemCollection.php | 9 ++++++++- src/Runtime/OData/ODataFormat.php | 1 + tests/Settings.php | 8 +++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/OneDrive/DriveItems/DriveItemCollection.php b/src/OneDrive/DriveItems/DriveItemCollection.php index 3e61ea44..bd8a255a 100644 --- a/src/OneDrive/DriveItems/DriveItemCollection.php +++ b/src/OneDrive/DriveItems/DriveItemCollection.php @@ -8,6 +8,9 @@ use Office365\OneDrive\ConflictBehavior; use Office365\Runtime\Actions\InvokePostMethodQuery; use Office365\Runtime\ClientRuntimeContext; +use Office365\Runtime\Http\RequestOptions; +use Office365\Runtime\OData\ODataMetadataLevel; +use Office365\Runtime\OData\V4\JsonFormat; use Office365\Runtime\ResourcePath; use stdClass; @@ -32,10 +35,14 @@ public function createFolder($folderName) $payload = array( "name" => $folderName, "folder" => new stdClass(), - "@microsoft.graph.conflictBehavior" => ConflictBehavior::Rename + "@microsoft.graph.conflictBehavior" => ConflictBehavior::Rename, ); $qry = new InvokePostMethodQuery($this,null,null,null, $payload); $this->getContext()->addQueryAndResultObject($qry, $folderItem); + $this->getContext()->getPendingRequest()->beforeExecuteRequestOnce(function (RequestOptions $request){ + $format = new JsonFormat(ODataMetadataLevel::MinimalMetadata); + $request->Headers["Content-Type"] = $format->getMediaType(); + }); return $folderItem; } diff --git a/src/Runtime/OData/ODataFormat.php b/src/Runtime/OData/ODataFormat.php index cfcb62eb..67220ba6 100644 --- a/src/Runtime/OData/ODataFormat.php +++ b/src/Runtime/OData/ODataFormat.php @@ -5,6 +5,7 @@ use Office365\Runtime\OData\V3\JsonLightFormat; +use Office365\Runtime\OData\V4\JsonFormat; abstract class ODataFormat { diff --git a/tests/Settings.php b/tests/Settings.php index d9c9f5cc..a229afee 100644 --- a/tests/Settings.php +++ b/tests/Settings.php @@ -1,9 +1,7 @@ "{$tenant_prefix}.onmicrosoft.com", @@ -13,8 +11,8 @@ 'AdminTenantUrl' => "https://{$tenant_prefix}-admin.sharepoint.com", 'Password' => $secure_vars[1], 'UserName' => $secure_vars[0], - 'ClientId' => "4b7eb3df-afc3-4b7d-ae1d-629f22a3fe42", - 'ClientSecret' => $secure_vars[2], + 'ClientId' => $secure_vars[2], + 'ClientSecret' => $secure_vars[3], 'RedirectUrl' => "https://{$tenant_prefix}.sharepoint.com", 'TestAccountName' => "jdoe2@{$tenant_prefix}.onmicrosoft.com", 'TestAltAccountName' => "wellis2@{$tenant_prefix}.onmicrosoft.com"