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

Some missing fluent API paths e.g. /me/drive/root/content

Open Ndiritu opened this issue 3 years ago • 5 comments

Missing paths should have an alternative URL path that is supported. You can find alternative paths from our API Reference

Ndiritu avatar Jul 06 '22 14:07 Ndiritu

Hi @Ndiritu, I'm trying to upgrade from RC4 to RC5 and I'm stuck with rewriting code for creating new UploadSession. Before update, I was creating the upload session this way:

/** @var UploadSession $driveItemUpload */
$driveItemUpload = $graph->createRequest('POST', '/drives/b!JAGSss-y9Uio20iGLHPPKbk_lZ1tsSxDijzVQZqZpmm_W6DxtFZNS5VR-gtQPhls/root/children/test-file.pdf/createUploadsession')
	->attachBody([
		'item' => (object) [
			'@microsoft.graph.conflictBehavior' => 'replace',
		],
	])
	->setReturnType(UploadSession::class)
	->execute();

but the proper fluent API class in the RC5 seems to be missing:

$request = $graph->drivesById('b!JAGSss-y9Uio20iGLHPPKbk_lZ1tsSxDijzVQZqZpmm_W6DxtFZNS5VR-gtQPhls')
	->root()
	->childrenById('test-file.pdf')
	->createUploadSession(); // <-- missing

Is the uploadSession method also missing or should I create upload session differently?

hubipe avatar Jul 08 '22 09:07 hubipe

@hubipe thanks for highlighting that missing path.

I tried to create the URL path based on the first path

The closest workaround I could come up with was:


$rootDriveId = 'b!JAGSss-y9Uio20iGLHPPKbk_lZ1tsSxDijzVQZqZpmm_W6DxtFZNS5VR-gtQPhls';
$itemId = 'root:/test-file.pdf:';

$itemProperties = new DriveItemUploadableProperties();
$itemProperties->setAdditionalData(['@microsoft.graph.conflictBehavior' => 'replace']);
$body = new CreateUploadSessionPostRequestBody();
$body->setItem($itemProperties);
$session = $graphServiceClient->drivesById($rootDriveId)->itemsById($driveItemId)->createUploadSession()->post($body)->wait();

Let me know if it works

Ndiritu avatar Jul 13 '22 09:07 Ndiritu

For the missing paths there's usually an alternative URL path from the docs that's supported, although we should support all.

Ndiritu avatar Jul 13 '22 09:07 Ndiritu

Hi @Ndiritu, thanks for the workaround. Unfortunately that does not work as the Graph API returns invalid request.

The library generates POST request to https://graph.microsoft.com/v1.0/drives/b%21JAGSss-y9Uio20iGLHPPKbk_lZ1tsSxDijzVQZqZpmm_W6DxtFZNS5VR-gtQPhls/items/root%3Atest-file.pdf/microsoft.graph.createUploadSession

with JSON body:

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

image

However you made a good point that itemsById() method also receives the path in the „colon“ notation,. So instead of

$itemId = 'root:test-file.pdf';

I used

$itemId = 'root:/test-file.pdf:';

and miraculously enough, that works:

image

So thank you very much

hubipe avatar Jul 14 '22 09:07 hubipe

You're welcome, feel free to share feedback on your overall experience with this version. What works well? What don't you like? What can we improve? Preferrably on the announcement post https://github.com/microsoftgraph/msgraph-sdk-php/issues/943

Ndiritu avatar Jul 14 '22 10:07 Ndiritu

The convention for alternative paths shall be to access resources from their root e.g. for Drive, using drive/... endpoints etc to minimize SDK size

Ndiritu avatar Oct 31 '22 13:10 Ndiritu