0

Last month I setup a Microsoft Services integration in my angular web app to access the company's personal account onedrive. So we use MSAL as the authentication service and the MSAL_INTERCEPTOR from msal-angular to authenticate our requests. All employees have the company's onedrive as a shared drive. Everything was working fine, but this week I received feedback that the model folder that should be copied with a new name isn't creating the subfolders and files.

Let me show my workflow to copy the model folder in the same parent folder with another name:

  1. Get the model folder's metadata and save the parent info:
GET https://graph.microsoft.com/v1.0/drives/SHARED_DRIVE_ID/items/SHARED_DRIVE_ID!52853:/05-DRM/01-Em%20Andamento/ORC-000_ANO-NOME%20DO%20CONTRATO-GESTOR

response:
{
  ...
  "id": "SHARED_DRIVE_ID!110649",
  "lastModifiedDateTime": "2021-05-21T15:28:55.567Z",
  "name": "ORC-000_ANO-NOME DO CONTRATO-GESTOR",
  "size": 0,
  "webUrl": "https://1drv.ms/f/s!ABM9Mjoi6dy8huA5",
  ...
  "parentReference": {
    "driveId": "SHARED_DRIVE_ID",
    "driveType": "personal",
    "id": "SHARED_DRIVE_ID!95075",
    "name": "01-Em Andamento",
    "path": "/drives/SHARED_DRIVE_ID/items/SHARED_DRIVE_ID!52853:/05-DRM/01-Em%20Andamento"
  },
  "fileSystemInfo": { "createdDateTime": "2021-02-11T13:47:04Z", "lastModifiedDateTime": "2021-03-29T13:50:23.99Z" },
  "folder": {
    "childCount": 8,
    "view": { "viewType": "thumbnails", "sortBy": "takenOrCreatedDateTime", "sortOrder": "ascending" }
  },
  "shared": { "scope": "users", "owner": { "user": { "displayName": "Nortan Diretores", "id": "SHARED_DRIVE_ID" } } }
}

  1. Make the copy request using the "parentReference"
POST https://graph.microsoft.com/v1.0/drives/SHARED_DRIVE_ID/items/SHARED_DRIVE_ID!52853:/05-DRM/01-Em%20Andamento/ORC-000_ANO-NOME%20DO%20CONTRATO-GESTOR:/copy

payload:
{
  "parentReference": { "driveId": "SHARED_DRIVE_ID", "id": "SHARED_DRIVE_ID!95075" },
  "name": "ORC-189_2021-Posto de Combustível 3M-Nichollas Gomes"
}

response:
Status Code: 202 Accepted
  1. The newly copied folder is created with all subfolders and files of the model folder.

  2. After four seconds of the copy request been accepted(Since there is no way to be notified of the copy process), I get the information of the new folder to get the web URL.

This workflow is working in my test on employee personal onedrive folders, and it was working with our shared folder too. But now, in the shared folder, when we reach step 4 of our workflow, only an empty new folder is created.

Trying to understand what is happening, I also noticed that when it made the copy request on the onedrive website is showed a copy operation that fails sometime later with the following error: Error: Try again or refresh page, but I can't debug this error. There is a way to debug this error?

Edit 1: I tried step 2 outside my web app with Postman and the same problem happened.

Edit 2: Request response made with postman:

Staus: 202Accepted    Time: 1596 ms    Size: 719 B

{
  "Date": "Sat, 22 May 2021 16:46:16 GMT",
  "Cache-Control": "no-store",
  "Transfer-Encoding": "chunked",
  "Location": "https://df.api.onedrive.com/v1.0/monitor/4s7kSj8n8-eF7gyNg40BOOKlQvmxjiQ9Yvana5Jl1l87mCOs4AGis4lO95DtmZaccjg-teKUNaY5EQtMya2RnjHfVY7DDbNXgCMYrQju89nzRdbwORmMhSxoy6mds4QfFOmAF92vSB7JL3J2456uxirjwjE3KCkN3KC9TfrJcxvGtFQU1VT7Euk6WMpoq3HeRcOwCtEP1GWuegI3qo1jFSj8PKoyIvTMrZ43snVoiBmjupBHiDlnTUsLkWzqUZ5v1X",
  "Strict-Transport-Security": "max-age=31536000",
  "request-id": "3a02e7bd-dbac-48e6-9a62-939ce0f2e3e0",
  "client-request-id": "3a02e7bd-dbac-48e6-9a62-939ce0f2e3e0",
  "x-ms-ags-diagnostic": {
    "ServerInfo": {
      "DataCenter": "Brazil South",
      "Slice": "E",
      "Ring": "3",
      "ScaleUnit": "000",
      "RoleInstance": "CP1PEPF00001A64"
    }
  }
}
7
  • (1) what you meant by company's personal onedrive - if i am not wrong you're talking about OneDrive for business provided by company per employee? (2) Share the Graph API error from the response, along with requestid, timestamp (either from postman or your application) Commented May 22, 2021 at 8:41
  • I believe you are aware that in most of the cases the copy action is performed asynchronously. The response from the API will only indicate that the copy operation was accepted or rejected, say due to the destination filename already being in use. So its worth to check you're not endup in the above scenario. Commented May 22, 2021 at 8:43
  • (1) No. I'm talking about personal OneDrives. The company has a personal account as each employee has one. For us in South America is too expensive to pay for OneDrive business account. (2) This is the point, there is no error. As I said, the request is accepted, the new folder is created in the right place, but somehow there is an internal error while copying the folder files. I will update my question with the requested information Commented May 22, 2021 at 16:27
  • Yes, I'm aware of this point. My scenario is to copy a base folder to a new folder without name conflict in the same parent folder. When I try the same operation in my personal OneDrive folder it works as expected, but in the company shared folder I have this problem Commented May 22, 2021 at 16:32
  • 1
    @Dev, I finally found the problem. I posted as an answer Commented Jun 23, 2021 at 13:08

1 Answer 1

1

Finally, I figured out what was the problem. The copy endpoint doesn't handle relative paths using an item as a base path like:

POST https://graph.microsoft.com/v1.0/drives/SHARED_DRIVE_ID/items/SHARED_DRIVE_ID!52853:/05-DRM/01-Em%20Andamento/ORC-000_ANO-NOME%20DO%20CONTRATO-GESTOR:/copy

So, I just changed in my workflow the copy endpoint using the item ID that I got when getting the folder metadata to get the parent info. Now my copy request is:

POST https://graph.microsoft.com/v1.0/drives/SHARED_DRIVE_ID/items/SHARED_DRIVE_ID!110649/copy

After this change my copy operation monitor result is:

{
    "errorCode": "",
    "operation": "itemCopy",
    "percentageComplete": 100.0,
    "resourceId": "SHARED_DRIVE_ID!290908",
    "status": "completed",
    "statusDescription": "Completed 10/10 files; 15906/15906 bytes"
}

Instead,

{
    "errorCode": "",
    "operation": "itemCopy",
    "percentageComplete": 0.0,
    "status": "notStarted",
    "statusDescription": "Completed 0/0 files; 0/0 bytes"
}

Thanks @Dev for all your support.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad to hear back @Kikuto!! Thanks for posting the resolution back to the community and upvoted it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.