Batch script example
@echo OFF
set PROTOCOL=http
set BASE_URL=ponton.dev.bearingx.io
set USERNAME=dev
set PASSWORD=test
set FILENAME=bearingx_upload.csv
set WORKDIR=
echo Starting automatic upload...
cd %WORKDIR% || goto :error
echo Logging in as '%USERNAME%' and saving cookie
curl "%PROTOCOL%://%BASE_URL%/login" ^
-H "authority: %BASE_URL%" ^
-H "cache-control: max-age=0" ^
-H "upgrade-insecure-requests: 1" ^
-H "origin: %PROTOCOL%://%BASE_URL%" ^
-H "content-type: application/x-www-form-urlencoded" ^
-H "accept: text/html,application/xhtml+xml,application/xml;q=0.9,im-
age/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
^
-H "sec-fetch-site: same-origin" ^
-H "sec-fetch-mode: navigate" ^
-H "sec-fetch-user: ?1" ^
-H "sec-fetch-dest: document" ^
-H "accept-language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7" ^
--data-raw "username=%USERNAME%&password=%PASSWORD%" ^
-c "bearingx_cookie.txt" ^
--silent ^
|| goto :error
echo Uploading file '%FILENAME%'
for /F %%I in ('curl "%PROTOCOL%://%BASE_URL%/api/orders/upload" ^
-H "authority: %BASE_URL%" ^
-H "accept: application/hal+json" ^
-H "origin: %PROTOCOL%://%BASE_URL%" ^
-H "sec-fetch-site: same-origin" ^
-H "sec-fetch-mode: cors" ^
-H "sec-fetch-dest: empty" ^
-H "accept-language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7" ^
-F "file=@%FILENAME%" ^
-b "bearingx_cookie.txt" ^
--silent ^
--write-out "%%{http_code}\n"') do set responseCode=%%I ^
|| goto :error
rem http response code should start with 20
if not "%responseCode:~0,2%" == "20" (
echo Return code: %responseCode%
goto :error
)
call :success
pause
exit /B 0
:cleanup
echo Cleaning up...
del bearingx_cookie.txt
exit /B 0
:success
echo Upload successfully done!
call :cleanup
exit /B 0
:error
echo Upload failed!
call :cleanup
exit /B 0
How do the scripts work?
The following description is based on the supplied script 'automaticUploadBearingx.bat'. The script is only an example of how an upload is possible.
The script calls the rest facade using simple curl commands. The first curl command creates a login
and saves the created cookie in a file for further use. This file should be located directly
next to the script and is called _'bearingx-cookie.txt'_. You should remember to delete this
cookie as soon as the script is finished. The next curl command uses the cookie created in the first step
created in the first step to authenticate the upload call. The second curl command calls _'/api/or-
ders/upload'_ of the rest facade and appends the file to be uploaded to the call.
Before executing, make sure that the line endings of the bash script are correct. It can happen
It can happen that the line endings are changed by copying and pasting (e.g. from an e-mail).
The Windows batch script can handle Windows and UNIX line endings.