microsoftgraph/msgraph-sdk-php

Conflict Behavior cannot be set for Drive Item Copy

Opened this issue · 2 comments

Describe the bug

I try to copy a file from folder A to folder B and I try to use @microsoft.graph.conflictBehavior but the request does not allow query parameters and it doesn't work if I add it to the body.

Expected behavior

I expected CopyRequestBuilderPostRequestConfiguration to have query options. Or for the CopyPostRequestBody->setAdditionalData(['@microsoft.graph.conflictBehavior' => 'rename']) to work.

How to reproduce

<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Drives\Item\Items\Item\Copy\CopyPostRequestBody;
use Microsoft\Graph\Generated\Models\ItemReference;


$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);

$requestBody = new CopyPostRequestBody();
$parentReference = new ItemReference();
$parentReference->setDriveId('6F7D00BF-FC4D-4E62-9769-6AEA81F3A21B');
$parentReference->setId('DCD0D3AD-8989-4F23-A5A2-2C086050513F');
$requestBody->setParentReference($parentReference);
$requestBody->setAdditionalData(['@microsoft.graph.conflictBehavior' => 'rename']);

$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->copy()->post($requestBody)->wait();

When there is already a file in the destination folder with the same name it doesn't do anything instead of renaming the new file.

SDK Version

2.10.0

Latest version known to work for scenario above?

1.110.0

Known Workarounds

No response

Debug output

No response

Configuration

No response

Other information

No response

Thanks for reporting this @JeroenTriptic.

As a temporary work-around, you can use the withUrl() method to pass a plain text URL with the query parameter:

$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->copy()->withUrl(
    $graphServiceClient->getRequestAdapter()->getBaseUrl()."/drives/{$driveId}/items/{$itemId}/copy"
)->post($requestBody)->wait();

Let me know if this works.

Sorry for the late response. The withUrl function does indeed function as a workaround.