Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Client bug]: .Copy.PostAsync(requestBody) return null. #2344

Closed
nklchaudhary opened this issue Feb 20, 2024 · 2 comments
Closed

[Client bug]: .Copy.PostAsync(requestBody) return null. #2344

nklchaudhary opened this issue Feb 20, 2024 · 2 comments

Comments

@nklchaudhary
Copy link

I am using the C# code provided on link

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

to copy folder or files. It work well but always return null.

var requestBody = new CopyPostRequestBody
{
ParentReference = new ItemReference
{
DriveId = "6F7D00BF-FC4D-4E62-9769-6AEA81F3A21B",
Id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
},
Name = "contoso plan (copy).txt",
};

var result = graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Copy.PostAsync(requestBody).GetAwaiter().GetResult();

Please suggest solution for it.

@andrueastman
Copy link
Member

Thanks for raising this @nklchaudhary

According to the REST documentation, the specific API does not return a body(202 response). Hence the null value.
To obtain the location header, you can pass options as below to get the location of the monitor.

            var requestBody = new CopyPostRequestBody
            {
                ParentReference = new ItemReference
                {
                    DriveId = "6F7D00BF-FC4D-4E62-9769-6AEA81F3A21B",
                    Id = "DCD0D3AD-8989-4F23-A5A2-2C086050513F",
                },
                Name = "contoso plan (copy).txt",
            };
            var headersInspectionHandlerOption = new HeadersInspectionHandlerOption()
            {
                InspectResponseHeaders = true // specific you wish to collect reponse headers
            };
            var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].Copy.PostAsync(requestBody, requestConfiguration => requestConfiguration.Options.Add(headersInspectionHandlerOption));

            var locationHeader = headersInspectionHandlerOption.ResponseHeaders["Location"];

The SDK does not support monitoring long running operations as described in the docs below, (this is tracked via microsoftgraph/msgraph-sdk-design#83)
https://learn.microsoft.com/en-us/graph/long-running-actions-overview?tabs=http

@nklchaudhary
Copy link
Author

Thank for responce. It help me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants