Graph API - Sharepoint copyItem with parentReference not working

Nobilex 46 Reputation points
2022-04-19T10:56:06.853+00:00

Hello everyone,

Ref:
https://learn.microsoft.com/en-us/graph/api/driveitem-copy?view=graph-rest-1.0&tabs=http

This API of copy drive item using graph api version 2.3.2 was working fine and since morning without any code change we are facing an issue. It seems that even if we pass parentReference, still it's copying into same directory as source file.

We are copying file from one folder to another folder with new path and name using graph API and kotlin

microsoftGraphClient.drives(documentStorage.driveId).items(fileToCopy.id)
.copy(it.newPath.getFilename(), parentReference)
.buildRequest()
.post()

Above code was working till 18th-April-2022 and not working since 19th-April-2022 morning. It is copying file in same directory as source file instead of copying into new location. We are using msgraph-sdk-java

Can someone look into it and revert?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,112 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Srinivasa Rao Darna 6,701 Reputation points Microsoft Vendor
    2022-04-19T12:37:59.083+00:00

    Hi @Nobilex ,

    I am able to reproduce this issue and there is a open case with Microsoft Engineering team for the driveitem-copy into same location.

    Will keep you informed about the progress.

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".

    4 people found this answer helpful.

  2. Praveen Narala 21 Reputation points
    2022-04-19T14:43:07.333+00:00

    @SrinivasaRaoDarnaMSFT-7657 Hi Srinivas, we are having the same issue while coping with the drive item from one folder to another folder. It is blocking our current release checks. Would be appreciated if this gets sorted ASAP. Thanks.

    2 people found this answer helpful.

  3. Curzio Carabelli 6 Reputation points
    2022-04-20T05:56:42.107+00:00

    The issue seems to have been fixed. I am again able to move files across folders through the Graph API by quoting the parentReference item Id


  4. Nobilex 46 Reputation points
    2022-04-21T11:11:07.353+00:00

    For temporary workaround if we pass path of parentReference along with Id then it's working fine. (ref: https://learn.microsoft.com/en-us/answers/questions/817792/recent-changes-to-the-driveitem-copy-method-of-the.html)

    fun main() {  
        val graphClient: GraphServiceClient<*> = GraphServiceClient  
                .builder()  
                .authenticationProvider(tokenCredAuthProvider)  
                .buildClient()  
      
        //Trigger copy operation with parent reference  
        val targetDirectory = ItemReference()  
        targetDirectory.id = "XXX"  
        targetDirectory.path = "XXX" // If we pass path for target directory item reference then it's working fine but with just id of target directory it will not work until they don't resolve it.   
          
        graphClient.drives("DRIVE_ID").items("Source_File_ID")  
                .copy(  
                        DriveItemCopyParameterSet  
                                .newBuilder()  
                                .withName("Target_File_Name")  
                                .withParentReference(targetDirectory)  
                                .build()  
                )  
                .buildRequest()  
                .post()  
    }