Skip to content

Authentication

Before interacting with the Predico API, you need to authenticate using your registered email and password. Ensure that you have completed the registration process and that your email address has been validated. If you haven't registered yet, please refer to the Forecaster Application section for instructions.

API Endpoints:

To authenticate with the Predico API you can use the following endpoints:

  • POST /api/v1/token - Authenticate and retrieve an access (bearer) token and a refresh token.
  • POST /api/v1/token/refresh - Obtain a new access token using a valid refresh token (without re-entering credentials).

Retrieving an Access Token

To authenticate with the Predico API, you need to obtain an access token using your credentials. This token will be used in the headers of your subsequent API requests to authorize your actions.

Here is how you can retrieve an access token using Python:

authentication.py
import requests

email = "your_email@example.com"
password = "your_password"

response = requests.post('https://predico-elia.inesctec.pt/api/v1/token',
                         data={'email': email, 'password': password},
                         timeout=30)

# Check if authentication was successful
if response.status_code == 200:
    token = response.json().get('access')
    print(f"Access Token: {token}")
else:
    print("Authentication failed. Please check your credentials.")
    print(f"Status code: {response.status_code}")

Download Full Example

JSON Example Response

Click to view Example Response
{
  "access": "jwt_access_token",
  "refresh": "jwt_refresh_token"
}

Token Lifetime and Refresh

Token expiry

  • Access tokens are short-lived (typically 1 hour). Include the access token in the Authorization: Bearer <token> header of every API request.
  • Refresh tokens have a longer lifetime. Use them with the /api/v1/token/refresh endpoint to obtain a new access token without re-entering your credentials.
Refresh an access token
import requests

refresh_token = "your_refresh_token_here"

response = requests.post(
    url="https://predico-elia.inesctec.pt/api/v1/token/refresh",
    json={"refresh": refresh_token}
)

if response.status_code == 200:
    new_access_token = response.json()["access"]
    print("New access token:", new_access_token)
else:
    print("Token refresh failed. Please re-authenticate.")
    print(f"Status code: {response.status_code}")

What's next?

Learn how to preview open market sessions on the Predico platform in the Listing Open Sessions section.