Batch script example
Example Batch-Script (.bat)
@echo OFF
set PROTOCOL=https
set BASE_URL=YourOwnUrl.app.bearingx.io
set USERNAME=YourUsername
set PASSWORD=YourPassword
set FILENAME=C:\Users\YourCSVPath\ExampleFile.csv
set WORKDIR=C:\Users\YourCSVPath
echo Starting automatic upload...
cd /d %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,image/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 script shown above. The script is only an example of how an upload is possible.
To execute the script, the variables must first be adapted. To do this, adjust the line of the URL, the user name, the password and the file path (purple lines) according to your own variables. Then save the file as a batch file (.bat) and execute it with a simple double-click.