Get all content metadata in json for space

vick April 10, 2016

Hello Everyone,

                       I am newbie to confluence rest api and I am trying to pull all content in my space. Below is link I am using:

https://servername/rest/api/content?spaceKey=space1&limit=2000&expand=version 

I believe this will pull all content metadata as json for space1, alongwith version.

This is not giving me everything in json. They is lot of missing metadata for space1, not appearing in json file.

Increasing limit is not making any difference in json content I am getting back.

Could you please help here, if I am doing something wrong?

Thanks in advance.

1 answer

0 votes
Aaron Knight April 10, 2016

Hi,

You need to ask Confluence to expand the response further. The Confluence API uses expandable elements - in your example, you've only expanded version. You can see which elements are expandable by looking at the _expandable element in the response when you do a GET.

It will look something like this:

"_expandable": {
        "container": "/rest/api/space/TEST",
        "metadata": "",
        "operations": "",
        "children": "/rest/api/content/1234/child",
        "history": "/rest/api/content/1234/history",
        "ancestors": "",
        "body": "",
        "version": "",
        "descendants": "/rest/api/content/1234/descendant",
        "space": "/rest/api/space/TEST"
      }

Each of these elements can be expanded further in the payload with the expand parameter on the request. If you're trying to get all content, try starting by expanding "body.storage,version".

From there, if there is still other meta info that you want, examine the result for more expandable markers and add them accordingly until you have all the data you need

Hope this helps!

vick April 11, 2016

Thanks Aaron for your response. This absolutely helped me to get more details for any specific title related information.
My issue is related to pages I am getting in result json .

I find out the limit restriction on my confluence. Even I mentioned limit as 2000, it is giving me only 200 back.

How I can increase system limit to a higher value?

Aaron Knight April 11, 2016

Hi,

I apologize for misunderstanding your question; I thought what you meant by "missing metadata" was that information about the page was missing, i.e, the content.

Your use of the limit parameter is correct, but it seems to me that the limit parameter has a ceiling of 200. If you look at the last part of the response:

"start": 0,
  "limit": 200,
  "size": 169,
  "_links": {
    "self": "https://localhost/confluence/rest/api/content?spaceKey=TEST&expand=version",
	"next": "/rest/api/content?spaceKey=TEST&expand=version&limit=5&start=5",
    "base": "https://localhost/confluence",
    "context": "/confluence"
  }

It'll note what the limit is on returned content. It seems that any value >= 200 is capped at 200; anything lower than that will match what you specify. I am not sure if it is possible to increase this maximum limit.

However, what you can do, is write your Java code for parsing in a while loop, that will keep calling the URL designated as next and aggregating the results.

You can do something like the following:

1) Parse the JSON, store results as you deem fit

2) Look for the _links block in the trailer

3) If next is not null, do a GET on the provided URL

4) Repeat until next is null

That way you'll aggregate the results and get everything. It is more service calls but will get you your data.

Hope this helps you!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events