Confluence REST api /rest/api/contentbody/convert/styled_view not rendering embedded images

Hi, I am trying to render the styled page content using REST api /rest/api/contentbody/convert/styled_view passing the storage value. Text content is correctly styled but for embedded image I see the image “?
Uknown Attachment”.
Is this a bug or I missed something to pass to API? As per doc inputs are just 2 value and representation, and I am passing both.

Can you please include your storage format here to what you’re trying to convert?

If the image is an attachment on a page that you want to include, make sure you set the page context by passing in the contentIdContext parameter.

Hi @mjensen - here is the code I used to retrieve the styled content -

httpClient = addon.httpClient(req);
		httpClient.get("/rest/api/content/19890194?expand=body.storage", function(apiErr, apiRes, apiBody){
			if (!apiErr && apiRes && apiRes.statusCode == 200) {
				var apiResponse = JSON.parse(apiBody);
				console.log(apiResponse.body.storage.value);
				var jsondata = {
					"value": apiResponse.body.storage.value,
				    "representation": "storage"
				};
				httpClient.post({
						url:"/rest/api/contentbody/convert/styled_view",
						body: JSON.stringify(jsondata),
						headers: {
							'Content-Type': 'application/json; charset=utf-8',
			                'X-Atlassian-Token': 'nocheck'
			            }
					},
					function(postErr, postRes, postBody){
						//console.log(postRes);
						// Rendering a template is easy; the `render()` method takes two params:
						// name of template
						// and a json object to pass the context in
						var postResponse = JSON.parse(postBody);
						console.log(postResponse);
						res.render('hello-world', {
							title : 'Embeddable Settings',
							html: postResponse.value
						});
					}
				);
			}

First I am retrieving the the storage value for the given page id and then passing it to contentbody/convert/styled_view API.
As you have mentioned what will be the value of “contentIdContext” and how can I get it? I dont see any reference of this in docs. I tried passing “/wiki”, pageId, attachment id etc for the param name “contentIdContext” as well as “context” in the post request to “contentbody/convert/styled_view”, but still getting same result.

Thanks

You might try using a cql argument:
rest/api/content/search?cql=id=[contentId]&expand=body.view
this usually does the trick form me. including macros, pictures etc.

Hi @maja.stach - thanks for the reply. But I am trying to render the styled view from content storage so that it can be used to show page with confluence style elsewhere. CQL will work for search API, but for contentbody/convert/styled_view its not an option as per docs (also tried on my local setup, does not work). Text part with style its rendering properly but not the attached images.

Instead of using /rest/api/contentbody/convert/styled_view if I use /rest/api/content/19890194?expand=body.styled_view it returns images. But macros are not expanded fully, e.g. JIRA issues macro does not retrieve issues or info macro is not styled properly.
Is there any other better way of retrieving confluence page as visible when in confluence without header/sidebar/navigation/footer?

Any ideas on how to render page in read only view with styles?

Hello, Parag. Did you find a solution to this issue? If yes could you provide it? I have similar issue and do not know how to fix it too.

1 Like

Hi @IvanRudyk, no, couldn’t find a way to get complete content of page when certain macros are embedded in confluence page which gets data using JS on browser side.

I also have a similar issue and can’t get the page to show properly using the export options :confused:

This problem can be solved by 2 way:

  • use anonimous access for this content (on plans Standart+)
  • replace img src. Original src in styled_view need to authorization. But it can be replace for shared links

Steps:

  1. when you get styled_view content, you need to find all <img…> tags. In each tag find attr ‘data-base-url’ = your address. Other images ignore.
  2. in this tags attrs you need is:
  • ‘data-linked-resource-container-id’ - id parent page
  • ‘data-linked-resource-id’ - id attachment
  1. now you can use api for ‘get URI to download attachment
    Link for GET method is ‘/wiki/rest/api/content/{data-linked-resource-container-id}/child/attachment/att{data-linked-resource-id}/download’ (only one moment, attachment id need prefix ‘att’).
  2. Delete all attrs in img tag, and set src from ‘location’ responce header. It link not need auth-user and picture must be render