Skip to content

Listing your continuous forecasts

This section provides an example of how to retrieve your continuous forecasts, submitted to Predico.

API Endpoints

To interact with the Predico API and retrieve information about your submissions and respective submitted forecast time-series, you can use the following endpoint:

Access Token Required

An access token must be included in the Authorization header of your request. If you haven't obtained an access token yet, please refer to the Authentication section.

Retrieving your continuous forecasts

Here's how you can retrieve the list your continuous forecasts (historical or future).

download_continuous_forecasts.py
import datetime as dt

import requests

# Predico instance URL. Switch BASE_URL to the environment you want to use:
#   - Playground: https://playground.predico.inesctec.pt
#   - Production: https://predico.inesctec.pt
BASE_URL = "https://predico.inesctec.pt"
API_URL = f"{BASE_URL}/api/v1"

# Authenticate via `/token` endpoint
access_token = "your_access_token_here"
headers = {
    'Authorization': f'Bearer {access_token}',
    'Accept': 'application/json'
}

# Challenge resource name.
resource_name = "wind_farm_1"

# Retrieve datetime range (last 30 days up to 3 days ahead, by default).
# Adjust to match the period you actually want to inspect.
now = dt.datetime.now(dt.timezone.utc).replace(minute=0, second=0, microsecond=0)
start_datetime = (now - dt.timedelta(days=30)).strftime("%Y-%m-%dT%H:%M:%SZ")
end_datetime = (now + dt.timedelta(days=3)).strftime("%Y-%m-%dT%H:%M:%SZ")

# Get challenges target resource identifier (UUID)
# (this is also available via the /market/challenge/ endpoint )
response = requests.get(
    url=f"{API_URL}/user/resource",
    params={'resource_name': resource_name},
    headers=headers,
    timeout=30
)

# Check if the request was successful
if response.status_code == 200:
    resources = response.json()
else:
    print("Failed to retrieve resource data.")
    print(f"Status code: {response.status_code}")
    print(f"Response: {response.content}")
    exit()

# Get resource ID:
resource_id = resources["data"][0]["id"]
print("Resource ID:", resource_id)

# Download continuous forecasts data for this resource:
params = {
    "resource": resource_id,
    "start_date": start_datetime,
    "end_date": end_datetime
}

next_url = f"{API_URL}/data/continuous-forecasts"
dataset = []

# -- Note: This will stop once all the samples are retrieved.
# -- next_url indicates the URL of the next page (pagination) to be requested)

first_request = True
while next_url is not None:
    print(f"Requesting data...\n{next_url}") # This may take a while
    # The first request needs `params`; subsequent `next_url` values returned
    # by the paginator already contain every query parameter, so we drop them.
    response = requests.get(
        url=next_url,
        params=params if first_request else None,
        headers=headers,
        timeout=30,
    )
    first_request = False
    print("Response status code:", response.status_code)
    # Check if the request was successful
    if response.status_code != 200:
        print("Failed to retrieve forecasts.")
        print(f"Status code: {response.status_code}")
        print(f"Response: {response.content}")
        exit("Exiting...")
    else:
        dataset += response.json()["data"]["results"]
        next_url = response.json()["data"]["next"]
        # -- Note: This will stop once all the samples are retrieved.

print("-"*79)
print(f"Retrieved {len(dataset)} records")
print("Continuous forecasts data (first 10 records preview):")
print(dataset[:10])

Download Full Example

JSON Example Response

After running the example script, you will have access your forecasted time-series. Note that we only store the latest forecast you have submitted for each timestamp.

If no data is received, please confirm if you are requesting data for the right resource identifier.

Click to view Example Response
{
  "code": 200,
  "data": {
    "count": 348,
    "next": null,
    "previous": null,
    "results": [
      {
        "datetime": "2025-04-26T17:00:00Z",
        "variable": "q10",
        "value": 0,
        "registered_at": "2025-04-26T15:59:41.472099Z"
      }
    ]
  }
}