How to create a Confluence API token (Personal Access Token)
- Log in to ECMWF Confluence.
- Click your profile icon in the top-right corner.
- Choose Settings → Personal Access Tokens.
- Click Create token.
- Enter a short name (e.g. Python page generator) and, if asked, set an expiry date.
- Tick Write content (create / update pages) so the script can publish pages.
- Click Create.
- Copy the generated token and store it safely — it will be shown only once.
Storing the API Token Securely
Instead of hardcoding the token directly in your script, you can store it as an environment variable in your
~/.bashrc file. This allows Python to read it automatically each time you run the script.
1. Add the token to your ~/.bashrc file
export CONFLUENCE_API_TOKEN="paste_your_token_here"
Then reload your configuration so it becomes active:
source ~/.bashrc
The token will now be available in all future terminal sessions.
2. Access the token inside your Python script
In your script, import the os module and read the token from the environment variable:
import os
API_TOKEN = os.getenv("CONFLUENCE_API_TOKEN")
if not API_TOKEN:
raise ValueError("API token not found. Please set the CONFLUENCE_API_TOKEN environment variable.")
3. Run your script normally
python3 generate_confluence_page.py