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

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

Open
dostjh opened this issue Dec 21, 2021 · 7 comments

Comments

@dostjh
Copy link

dostjh commented Dec 21, 2021

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
Copy link
Member

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:

public static async Task<string> MoveAsync(this IContentDomain confluenceClient, string contentId, Positions position, string targetId, CancellationToken cancellationToken = default)

Copy:

public static async Task<Content> CopyAsync(this IContentDomain confluenceClient, string contentId, CopyContent copyContent, IEnumerable<string> expandCopy = null, CancellationToken cancellationToken = default)

@Lakritzator
Copy link
Member

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
Copy link
Member

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

@dostjh
Copy link
Author

dostjh commented Jan 6, 2022

@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
Copy link
Author

dostjh commented Jan 7, 2022

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
Copy link
Author

dostjh commented Jan 7, 2022

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
Copy link
Member

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.

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

No branches or pull requests

2 participants