msgraph-sdk-php icon indicating copy to clipboard operation
msgraph-sdk-php copied to clipboard

Drive – create upload session does not work since @RC6

Open hubipe opened this issue 3 years ago • 0 comments

Hi, since 2.0.0-RC6 creating upload session stopped to work. Here is a code sample, which used to work until RC5:

use Microsoft\Graph\Generated\Drives\Item\Items\Item\CreateUploadSession\CreateUploadSessionPostRequestBody;
use Microsoft\Graph\Generated\Models\DriveItemUploadableProperties;

$itemProperties = new DriveItemUploadableProperties();
$itemProperties->setAdditionalData([
	'@microsoft.graph.conflictBehavior' => 'replace',
]);

$body = new CreateUploadSessionPostRequestBody();
$body->setItem($itemProperties);

$session = $graph->drivesById($driveId)
	->itemsById('root:/test-file.pdf:')
	->createUploadSession()
	->post($body)
	->wait();

The graph API returns HTTP 400 Bad Request.

The problem is within a body of the request. Until the RC5, the request body was:

{
    "item": {
        "@microsoft.graph.conflictBehavior":"replace"
    }
}

image

but since RC6 the request body is:

{
    "item": {
        "@odata.type": "#microsoft.graph.driveItemUploadableProperties",
        "@microsoft.graph.conflictBehavior": "replace"
    }
}

image

It seems, that Graph API does not understand the @odata.type item property. Is it necessary to include the @odata.type property?

hubipe avatar Sep 23 '22 09:09 hubipe