I am attempting to query Confluence knowledge base pages using the API and failing.
I have researched the api and have the following:
Browsing Content
curl -u admin:admin http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
Read Content and Expand the Body:
curl -u admin:admin http://localhost:8080/confluence/rest/api/content/3965072?expand=body.storage | python -mjson.tool
What I actually want to do is dump out the contents of a page / pages in a "Space" as Confluence calls it to a file, or on screen.
This is an actual page:
"https://bob.atlassian.net/wiki/spaces/BKB/pages/1234567/BOB KNOWLEDGE BANK"
And this is an example I found of using the REST API to do what I want:
curl -u admin:admin -G "http://myinstance.address:8090/rest/api/content/search" --data-urlencode "cql=(type=page and space=low and title ~ "LOWERTOWN")" \ | python -m json.tool
How I am translating what I have researched:
curl -u "[email protected]:12345678" -G "https://bob.atlassian.net/rest/api/content/search" --data-urlencode "cql=(type=page and space=BKB and title ~ "BOB KNOWLEDGE BANK")" \ | python -m json.tool
Which results in this error:
curl: (3) URL using bad/illegal format or missing URL
No JSON object could be decoded
I have grabbed my logic here from this site:
And I am assuming I have misunderstood this:
/rest/api/content/search
And where it belongs in my curl statement and linking it to the knowledge base. I am also unsure if applying the -mjson.tool is applicable in my case or if I actually have it installed / need to verify that.
Can you help me interpret this correctly?
CodePudding user response:
You are almost there! You just need to pass cql
as query parameter to the service as mentioned here in Atlassian documentation:
curl --request GET
--url 'https://your-domain.atlassian.net/wiki/rest/api/search?cql={cql}'
--header 'Authorization: Bearer <access_token>'
--header 'Accept: application/json'