How to pass the page_title and space_key as input variable in confluence API using curl?
Asked by Bhakya:

Hi Folks,

Could anyone share the confluence api curl syntax having input of page-title and space key.

I would appreciate if anyone send the CURL in order to get the page_id from JSON.

Thanks in advance


Answers:
author: Bhakya
body: [@Mario Abud](/t5/user/viewprofilepage/user-id/2238508) Thanks for your reply.

I have tried the below

curl -u admin:admin -X GET "<https://mydomain.net/confluence/rest/api/content?title={page_title>}%20Title\&spaceKey={Key_name}\&expand=history"

Getting response like "No JSON object could be decoded".

Could you please let me know if i did anything wrong.

comments: author: Mario Abud
body: Hi [@Bhakya](/t5/user/viewprofilepage/user-id/3733194)

Try this please, curl -u username:password -H "Content-Type: application/json" -X GET "http://localhost:8080/rest/api/content?spaceKey=TST\&title=PageTitle\&expand=history"

You have to change the part that says username, password,PageTitle and TST, with your data

Do you have Confluence Server or Confluence Cloud?

Regards


author: Bhakya
body: [@Mario Abud](/t5/user/viewprofilepage/user-id/2238508)

I am having Confluence cloud


author: Mario Abud
body: Okay for Confluence Cloud first generate an api token <https://id.atlassian.com/manage/api-tokens>, sorry I thought you had Confluence Server

I just tried the code and it worked

curl -D- \\ -u email:apitoken \\ -X GET \\ -H "Content-Type: application/json" \\ [https://change.atlassian.net/wiki/rest/api/content?spaceKey=CHANGE\&title=Change\&expand=history](https://change.atlassian.net/wiki/rest/api/content?spaceKey=CHANGE&title=Change&expand=history)

Regards


author: Bhakya
body: [@Mario Abud](/t5/user/viewprofilepage/user-id/2238508) .How can i came to know whether i am using confluence server or cloud?

I need to update the confluence page through jenkins Job


author: Mario Abud
body: You can check this page [@Bhakya](/t5/user/viewprofilepage/user-id/3733194) [How Do I Know What Version of Confluence Is Running?](https://confluence.atlassian.com/confkb/how-do-i-know-what-version-of-confluence-is-running-179441565.html)

And check this page please [How to publish a Confluence(Cloud) Page in Jenkins](https://serverfault.com/questions/953013/how-to-publish-a-confluencecloud-page-in-jenkins)

[Confluence Publisher](https://plugins.jenkins.io/confluence-publisher)

Regards


author: Bhakya
body: [@Mario Abud](/t5/user/viewprofilepage/user-id/2238508) ,

Thanks for the information.

I have already gone through this page ([How to publish a Confluence(Cloud) Page in Jenkins](https://serverfault.com/questions/953013/how-to-publish-a-confluencecloud-page-in-jenkins) ) in which am not sure how to get the page id dynamically having inputs of Page title or space key.Could you please help me out how to get the page id of the confluence from Jenkins.

Thanks,

Bhakya


author: Bhakya
body: I just tried to get the Page_id using below

$(curl -u admin:XXX -X GET \\ "[https://XXX.net/wiki/rest/api/content?title=${Confluence_Page_Title}\&spaceKey=${Confluence_Space_Key](https://XXX.net/wiki/rest/api/content?title=${Confluence_Page_Title}&spaceKey=${Confluence_Space_Key)}" \| python -mjson.tool \| grep '\\"id\\"' )

Getting 404 error since the key and page title are available in confluence.


author: Bhakya
body: Thank you


author: Mario Abud
body: Hi [@Bhakya](/t5/user/viewprofilepage/user-id/3733194) , you can see if this [code](https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/) works for you

```
curl -u admin:admin -X GET "http://localhost:8080/confluence/rest/api/content?title=myPage%20Title&spaceKey=TST&expand=history" | python -mjson.tool
```

Regards


Tags: new-to-confluence