Zum Inhalt

Read List of Data

In the myfiber API, a list of data can be obtained by using No Offset Pagination (or Cursor Pagination) to page through results.

To control pagination, two query parameters are available for these endpoints:

  • _page_cursor - a unique ID marking the starting point for the next page (defined in the next URL)
  • _page_size - optional, the number of records to receive per page (default: 500, max: 2000)

Example: Read CANs

Particular Coverage Access Nodes (CANs) can be read by specifying any of the query parameters located at the endpoint.

Suppose we would like to read the list of all nodes where token = operation. Here are the steps how to execute this with No Offset Pagination.

Steps

  1. Request the First Page

    In the first page request, simply use the base URL and append the token = operation filter. Optionally, you may set a different _page_size query parameter from the default, if desired.

    $ curl --request GET "https://api.myfiber.at/v2/cov/nodes/?token=operation" \
    $  --header "Authorization: Bearer <access_token>" \
    $  --header "Accept: application/json"
    ---> 100%
    
    HTTP/1.1 200 OK
    date: Thu, 27 Mar 2025 19:25:35 GMT
    ...
    x-page-size: 500
    x-page-count: 163
    link: <https://api.myfiber.at/v2/cov/nodes/?token=operation>; rel=self, <https://api.myfiber.at/v2/cov/nodes/?token=operation&_page_cursor=01953216-aaaa-788e-986e-822e157e5114&_page_size=500>; rel=next
    
    [
      {"tenant": "fiberpark", ...
      {"tenant": "fiberpark", ...
      ...
    ]
    

  2. Retrieve the next URL

    The next URL for pagination is provided in the API response header in the link field. The method for extracting the next URL varies depending on the programming language used. The Link header is common implementation for pagination.

    For instance, in the Python script below, we use the httpx package, which parses the links from the response header and stores them in the response.links object. If another page is available to retrieve, it will include a "next" object with the relevant "url" value for accessing the next page:

    next_url = response.links.get("next", {}).get("url")
    
  3. Request Next Page

    Use the next_url obtained in Step 2 in your next request:

    request GET "https://api.myfiber.at/v2/cov/nodes/?token=operation&_page_cursor=01953216-aaaa-788e-986e-822e157e5114&_page_size=500"             
    
  4. Repeat Until Completion

    Repeat Steps 2 and 3 until no next URL is provided or the last page returns an empty page of data ([]), indicating all records have been retrieved.

Example Script (Python)

The following script automates pagination to fetch all pages of data. Please replace the <client_id> and <client_secret> placeholders with your credentials. The attributes token_url and scope are provided via API documentation.

# /// Pagination Script
# requires-python = ">=3.11"
# dependencies = [
#     "httpx",
#     "httpx-auth"
# ]
# ///

import os
import httpx
from httpx_auth import OAuth2ClientCredentials

BASE_URL = "https://api.myfiber.at/v2"
RESOURCE = "/cov/nodes/"
HEADERS = {"Content-Type": "application/json"}

CLIENT_ID = os.environ.get("client_id")
CLIENT_SECRET = os.environ.get("client_secret")

oauth2_cred = OAuth2ClientCredentials(
    token_url="<token_url>",            # fill in token_url from API documentation
    scope="<scopes>"                    # fill in (list of) scopes from API documentation
    client_id=CLIENT_ID,            
    client_secret=CLIENT_SECRET,
)

results_list = []
next_url = BASE_URL + RESOURCE          # mind the slashes "/"

with httpx.Client(headers=HEADERS, auth=oauth2_cred) as client:
    while next_url:
        response = client.get(url=next_url)
        results_list.extend(response.json())
        next_url = response.links.get("next", {}).get("url")

print(f"Total records: {len(results_list)}")

You may call this script with the environment variables set as ...

Shell Script for macOS/Linux
client_id="YOUR_ID" client_secret="YOUR_SECRET" python3 script.py
Windows PowerShell
client_id="YOUR_ID" client_secret="YOUR_SECRET" python3 script.py
Windows cmd.exe
set client_id=YOUR_ID&& set client_secret=YOUR_SECRET&& python script.py