dapplo / Dapplo.Confluence

An Atlassian confluence client for .NET
MIT License
34 stars 20 forks source link

REQUEST: Method to copy content from a source content ID to a target content ID #57

Open dostjh opened 2 years ago

dostjh commented 2 years ago

Confluence REST API supports copying content from a source content to a target content. I'm working on a project today in Dapplo.Confluence that would have made extensive use of that call had it been available. As is, I'm having to copy the data from a source page, create or get a target page, and then copy each property of the source page into the target page.

https://community.developer.atlassian.com/t/added-move-and-copy-page-apis/37749

Lakritzator commented 2 years ago

I've added both methods, and these should be available with version 1.0.25. BUT I didn't have time yet to write test cases, the calls might just give an exception... I will do so ASAP, but I have to take care of my kid, and do not know how long that might take.

I though if you have time and have a test server, you can already start integrating the calls.

Move: https://github.com/dapplo/Dapplo.Confluence/blob/a62580c026e6ef088e5dd02f435e85fb9bd018b3/src/Dapplo.Confluence/ContentExtensions.cs#L340

Copy: https://github.com/dapplo/Dapplo.Confluence/blob/a62580c026e6ef088e5dd02f435e85fb9bd018b3/src/Dapplo.Confluence/ContentExtensions.cs#L361

Lakritzator commented 2 years ago

I managed to write a test case and I found some issue, which I fixed. In the build for that fix there was an error and it seems that Json wasn't serialized correctly, the destination information for the CopyAsync wass missing: {"destination":{"value":"550731777"},"pageTitle":"Copied page"}

I seem to have fixed it, if you do still get an error from Confluence "Invalid destination", that might be the issue. Anyway, got Dapplo.Confluence version 1.0.27 available with the copy & move.

Now I need to sleep, it's way past midnight.

Lakritzator commented 2 years ago

@dostjh did you manage to have a look at this?

dostjh commented 2 years ago

@Lakritzator sorry for the delay in reply. Was enjoying the holidays. :) I don't have access to a test server myself unfortunately, and I'd have to ask our team to integrate in your change to our artifactory instance at work, but I'll do that today and let you know the result there. Greatly appreciate your looking into this!

dostjh commented 2 years ago

EDIT: I think I understand the problem. This API endpoint has been enabled for Confluence Cloud, but I don't think it has for Confluence Server which is the instance I'm running against, so I may be out of luck here. Hope others find your change useful, but I won't be much use in assessing the implementation. My apologies.

--ORIGINAL COMMENT--

So, I'm getting an error, but maybe I'm utilizing the code in correctly. The error is null for uri: https://[path to instance]/confluence/rest/api/content/255657627/copy

Here is the relevant sample code I'm using:

        var copyContent = new CopyContent()
    {
        CopyAttachments = true,
        Destination = new CopyPageRequestDestination()
        {
            DestinationType = CopyDestinations.ParentPage,
            Value = "182753302"
        },
        PageTitle = "Test Copy via API"
    };

    var result = _client.Content.CopyAsync(255657627, copyContent).Result;
dostjh commented 2 years ago

If anyone who stumbles across this issue wants to follow this API method not being implemented for Confluence Server/Data Center, it's tracked here: https://jira.atlassian.com/browse/CONFSERVER-60397

Lakritzator commented 2 years ago

I should have asked if it was for server or cloud!

I just added a check in the code, so you will get an exception, which makes the issue more clear.