API key permissions for Confluence page URL fetching

Hello!

I’m trying to use Confluence rest api to get URLs for Confluence pages with certain title. I’m trying to create a granular API key to get the job done, but can’t find a working subset of permissions. I tried giving all read + search permissions, but I get “unauthorized” error.

My script works well with unscoped API key, all possible permissions to Confluence.

Here’s how I call the API:

def find_confluence_page(external_id: str) -> str | None:
    """Search Confluence for a page containing the incident ID in its title."""
    # Use Basic Auth with email:token
    auth = (USER_EMAIL, CONFLUENCE_API_TOKEN)

    headers = {
        "Content-Type": "application/json",
    }

    params = {
        "cql": f'title ~ "{external_id}" AND space = "my_space"',
        "limit": 1,
    }

    try:
        response = requests.get(
            f"{CONFLUENCE_BASE_URL}/rest/api/content/search",
            auth=auth,
            headers=headers,
            params=params,
            verify=False,
        )
        response.raise_for_status()

        results = response.json()
        if results.get("results"):
            page = results["results"][0]
            return f"{CONFLUENCE_BASE_URL}{page['_links']['webui']}"

        return None
    except Exception as e:
        logging.warning(f"Failed to search Confluence for {external_id}: {e}")
        return None

What would be the subset of permissions with least permissions to get the script working? Thanks a ton!

@RistoIlomki the API documentation for that endpoint lists the search:confluence scope as required.