1
votes

I have developped a webapp using Ms Graph API to copy files from sharepoint libraries to other sharepoint libraries (all online).

I call the Graph API copy like this:

POST https://graph.microsoft.com/v1.0/drives/SrcDriveID/items/*SrcDriveItem*/[email protected]=replace

{ "parentReference" :  { "driveId": "*DestDriveID*",  "id": "*DestParentDriveItem*" },  "@microsoft.graph.conflictBehavior":"replace" } }

I receive the following error:

<Internal Server Error> <{"error": {"code": "generalException","message": "An unspecified error has occurred.","innerError": {"request-id": "0623069a-7071-47f9-be92-48d58902f300","date": "2020-05-06T21:11:07"}}}>

The webapp is using delegated permissions and only work accounts. The grants given to this app for Graph API are:

  • Directory.read.all
  • File.ReadWrite
  • Sites.Read.All
  • User.Read
  • File.ReadWrite.All

The issue is systematic on my production environment. I don't have it on my dev environment although the permissions are the same. The users triggering the webapp (and the related bearer key) have Read / Write access on the source and the destination sharepoint libraries. On the destination they are members and not owners.

Any help is welcome !

Thanks in advance

UPDATE: Adding the .NET C# Code:

        StringBuilder jsonData = new StringBuilder("{ \"parentReference\" :  { \"driveId\": \"" + DestDriveID + "\",  \"id\": \"" + DestParentDriveItem + "\" },  \"@microsoft.graph.conflictBehavior\":\"replace\" } }");

        String restCallUrl;

        if (overwrite)
        {
            restCallUrl = _baseUri + "drives/" + SrcDriveID + "/items/" + SrcDriveItem + "/[email protected]=replace";
        }
        else
        {
            restCallUrl = _baseUri + "drives/" + SrcDriveID + "/items/" + SrcDriveItem + "/copy";
        }


        HttpClient apiCallClient = new HttpClient();

        HttpRequestMessage apiRequest = new HttpRequestMessage(HttpMethod.Post, restCallUrl);
        apiRequest.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
        HttpContent addAttachmentBody = new StringContent(jsonData.ToString(), Encoding.UTF8, "application/json");
        apiRequest.Content = addAttachmentBody;

        apiRequest.Headers.Add("Authorization", "Bearer " + _accessToken);

        HttpResponseMessage apiCallResponse = await apiCallClient.SendAsync(apiRequest);



        if (apiCallResponse.StatusCode != System.Net.HttpStatusCode.Accepted)
        {
            String requestResponse = await apiCallResponse.Content.ReadAsStringAsync();

            _mylog.Warning("Copy -<" + apiCallResponse.ReasonPhrase + "> <" + requestResponse + ">");
            throw new DllNotFoundException();
        }

UPDATE I realized that the jsonData was not well balanced. I correct with the following:

StringBuilder jsonData = new StringBuilder("{ \"parentReference\" :  { \"driveId\": \"" + DestDriveID + "\",  \"id\": \"" + DestParentDriveItem + "\" },  \"@microsoft.graph.conflictBehavior\":\"replace\",  \"name \":  \"" + DstFileName + "\"  }");

or

StringBuilder jsonData = new StringBuilder("{ \"parentReference\" :  { \"driveId\": \"" + DestDriveID + "\",  \"id\": \"" + DestParentDriveItem + "\" },  \"@microsoft.graph.conflictBehavior\":\"replace\" }");

both are failing with the same error.

The last one gave me:

Copy -<Internal Server Error> <{"error": {"code": "generalException","message": "An unspecified error has occurred.","innerError": {"request-id": "ebf30e17-b4be-4994-bf86-bc3b86834d12","date": "2020-05-09T07:30:42"}}}>

UPDATE: I have done the exact same action on Graph explorer and it did work

https://graph.microsoft.com/v1.0/drives/b!fffffffffqv/items/01GEGKyyyyyyuuHR/[email protected]=replace
{ "driveId": "b!yyyyy",  "id": "uuuuuu" },  "@microsoft.graph.conflictBehavior":"replace" }

It does work with Graph API explorer as soon as File.ReadWrite and Files.ReadWrite.All are set. I'll double check that they are applied on my webapp. UPDATE Files.ReadWrite.All permission is set to application while delegated is expected. Awaiting the change. UPDATE Issue fixed by above change

1
Can you provide complete error information?Carl Zhao
Hello @CarlZhao, I'm happy to give anything related to the issue but here I don't see much what I could give. Below the code. Maybe I missed something. HttpResponseMessage apiCallResponse = await apiCallClient.SendAsync(apiRequest); if (apiCallResponse.StatusCode != System.Net.HttpStatusCode.Accepted) { String requestResponse = await apiCallResponse.Content.ReadAsStringAsync(); _mylog.Warning("Copy -<" + apiCallResponse.ReasonPhrase + "> <" + requestResponse + ">"); throw new DllNotFoundException(); }chu

1 Answers

0
votes

File.readwrite.all permission was set as application while delegated was expected.