Can we get Confluence Page ID via REST for a given page URL

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2017

I need Confluence Page ID and page owner values using REST api for a given Confluence URL. Is it possible?

2 answers

1 accepted

6 votes
Answer accepted
AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 21, 2017

Hi Srinivas,

This page has an example of how to get the page ID and creator if you have the URL (which includes the space key and page title):

Confluence REST API Examples

Please see the heading, "Find a page by title and space key".

There are no page owners in Confluence, but perhaps finding the creator will be of help.

Please let us know any follow up questions.

Thanks,

Ann

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 21, 2017

Thank you

Hung Nguyen February 25, 2020

In some case, the page is given with a url with no Title at all. It may be a tiny url. Is there anyway we can get the page Id from that, using REST API?

Like Moritz_Ringler likes this
Hung Nguyen April 2, 2020

The way I manage around in this case (no title, no space) is to do one extra step to 'get' this tiny url content first, then extract the space, title and id from the metadata content.

They are kept in the attributes with names ajs-space-key, ajs-page-title and ajs-latest-page-id. 

Phaneendra chitta September 30, 2021

Hi,

@AnnWorley Can I get only page ID as a response in JSON instead of all the info of the page?

Andrey Tetyuev July 13, 2023

@Phaneendra chitta: AFAIK - there is no way around to get the page ID from short link except to "open the link" (e.g. via curl) and then read the ID from retrieved page content as described below in the comment from @Partha Kaushik on 24.06.2021.

I don't know - why it should be avoid to retrieve the page content from short link, but if it's really strictly prohibited for some reason - a workaround could be to iterate via REST API through all pages at confluence server (i.e. get all spaces, then within all spaces iterate over all pages and their sub-pages starting from each space-homepage). During the iteration compare the short links of pages with requested one and in this way - get the page ID. But this workaround is really ugly and will take longer as direct download of page content...

0 votes
Partha Kaushik June 24, 2021

Here is a code snippet in Python:

import os, re, sys, json, requests
# In the page URL, replace the + symbols with %20
confPage = https://confluence.mydomain.com/display/TST/My%20Specific%20Page
auth = (confUsername, confPassword)
headers = { 'Content-type': 'application/json', 'Accept': 'application/json' }
res = requests.get(confPage)  
#print (res.content)
matched_lines = [line for line in (res.text).split('\n') if "ajs-page-id" in line]
if len(matched_lines) == 0: exit("Page ID not found")
# Output line example: <meta name="ajs-page-id" content="544428643"> , need that page-id
pageID = (matched_lines[0].split()[2].strip('<').strip('>').split('"')[1])
print (" Page ID: " + pageID)

Rakesh Narayanaswamy September 21, 2023

confPage = https://confluence.mydomain.com/display/TST/My%20Specific%20Page  did not work for me instead I had to use REST end point 

confPage = https://confluence.mydomain.com/display/rest/api/content/464194260

 

Are you sure we can use normal https url that we use in browser in script ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events