Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get all pages from all spaces with a specific label using Rest API and a Service Acccount?

Peter Rossum_ van
January 27, 2026

I am using a Service Account with admin permissons and an API-token (=not Oauth2).
When I try to get all pages from all spaces with a specific label:

GET <siteBaseUrl>/wiki/api/v2/labels/{id}/pages
I only get the pages from the spaces that are open for all users. So I thought I need to enable an Admin Key.

However when I try to POST <siteBaseUrl>/wiki/api/v2/admin-key  I get an error: "Unauthorized; scope does not match"

So, how can I get all pages from all spaces with a specific label?

2 answers

1 accepted

0 votes
Answer accepted
Marc -Devoteam-
Community Champion
January 27, 2026

Hi @Peter Rossum_ van 

The Service Account would need to have access to all spaces.

Other pont, I don't think a service account can use this API endpoint (no scopes are defined).

But I might be wrong,  have you made the service account a Confluence Admin? Could you try the API call to get an admin key again?

Peter Rossum_ van
January 27, 2026

@Marc -Devoteam-  Thanks for the quick answer!
The Service Account was already defined as App Admin in our Confluence App. That did not help. I thought the way to go was to enable the Admin Key. Too bad.
--
So, as I understand we need to make sure this Service Account has access to all spaces.
So, next steps for us is to define an automation flow to grant access for this Service Account to all spaces where it did not yet had access.

Marc -Devoteam-
Community Champion
January 27, 2026

Hi @Peter Rossum_ van 

Or Have a normal account, your own and try the same action.

Does that work, I think it would.

Otherwise do you have a default admin group on all confluence spaces, add the service account in there.

Yes or create an automation to achieve the permission update.

0 votes
Aaron Pavez _ServiceRocket_
Community Champion
January 27, 2026

Hi @Peter Rossum_ van 

I recommend going over the docs again on how to use the admin key:

https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-admin-key/#api-admin-key-get

The community post

https://community.atlassian.com/forums/Confluence-Cloud-Admins-articles/Introducing-admin-key-support-for-REST-APIs/ba-p/2996259

How can I execute subsequent REST API calls using my admin key?

Organization or site admin users can make subsequent calls to any of our existing REST APIs using their admin keys by simply adding the following HTTP header to their requests:

HTTP Header Name: Atl-Confluence-With-Admin-Key

HTTP Header Value: true

---

First, POST the admin key to enable it using the right JSON body.

Then you need to call this first, and then use the admin key in the headers of the other script.

An example:

API_ENDPOINT = f"{BASE_URL}/wiki/api/v2/admin-key"

# === REQUEST ===
response = requests.post(
API_ENDPOINT,
headers=headers,
auth=AUTH,
json=payload # Use `json=` instead of `data=` with `json.dumps`
)

Here, the API endpoint is the admin key. Hope this helps!

Regards

Peter Rossum_ van
January 27, 2026

Aaron,
Thanks for your answer.
And what you describe is exactly what I do.
The body I use is:  "durationInMinutes": 60
And just do be clear....
When I do NOTHING with the Admin Key and I use an API to get all spaces, it gives me only the spaces where the Service Account has access to. So, autharization is okay, endpoint is okay. Only the permissions are not suffient.
Btw. we have a confluence app using "Teamwork Collection Enterprise". Is that some modern version of Enterprise?
The documentation of the Admin-Key API says:

Scopes

Forge and OAuth2 apps cannot access this REST resource.

Connect apps cannot access this REST resource.

But I am using a Service Account with admin permissions.
So, I am still stuck.

 

Aaron Pavez _ServiceRocket_
Community Champion
January 27, 2026

Hi @Peter Rossum_ van 

Can you share a screenshot of the permissions you've set for the service account?

What authentication type youve selected?

If you selected API, what scopes ahve you selected?

What access does it have?

Regards

Marc -Devoteam-
Community Champion
January 27, 2026

Hi @Peter Rossum_ van 

Did you add an oath2 token to the service account, as the admin key option in API requires this..

An AT won't work for this.

Or grant the service account Site admin permissions

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
ENTERPRISE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events