The following code snippet is intended for downloading files from FMS using a batch script on the Windows command line. Please use this at your own risk.
For users who download files regularly, we recommend implementing the logic in a programming language. Batch scripts are fragile when handling special characters — for example, if your password contains symbols, they must be properly escaped.
@echo off
setlocal enabledelayedexpansion
REM Store credentials in variables
set "KEYCLOAK_URL=https://keycloak.tp.entsoe.eu/realms/tp/protocol/openid-connect/token"
set "FMS_URL=https://fms.tp.entsoe.eu/downloadFileContent"
set "CLIENT_ID=tp-fms-public"
set "USERNAME=YOUR_TP_EMAIL_ADDRESS"
set "PASSWORD=YOUR_TP_PASSWORD"
REM Step 1: Get the token
curl -s --location "%KEYCLOAK_URL%" ^
--header "Content-Type: application/x-www-form-urlencoded" ^
--data-urlencode "client_id=%CLIENT_ID%" ^
--data-urlencode "grant_type=password" ^
--data-urlencode "username=%USERNAME%" ^
--data-urlencode "password=%PASSWORD%" > response.json
REM Step 2: Extract access_token properly
set "token="
for /f "usebackq tokens=1,* delims=:" %%A in ("response.json") do (
echo %%A | findstr /i "\"access_token\"" >nul
if !errorlevel! == 0 (
set "line=%%B"
set "line=!line:~1!"
for /f "tokens=1 delims=," %%C in ("!line!") do (
set "token=%%~C"
set "token=!token:"=!"
)
)
)
echo Token: !token!
REM Step 3: Use token to download a file from FMS
curl --location "%FMS_URL%" --header "Authorization: Bearer !token!" --header "Content-Type: application/json" --data "{\"folder\": \"/TP_export/ActualTotalLoad_6.1.A/\", \"filename\": \"2014_12_ActualTotalLoad_6.1.A.csv\",\"topLevelFolder\": \"TP_export\", \"downloadAsZip\": false }" -o downloaded_file.csv
endlocal
pause
Comments
0 comments
Article is closed for comments.