Shell script example
#!/bin/bash
export PROTOCOL="https"
export BASE_URL='ponton.dev.bearingx.io'
export USERNAME='dev'
export PASSWORD='test'
export FILENAME='./bearingx_upload.csv'
export WORKDIR='./'
cleanup() {
echo "Cleaning up..."
rm bearingx_cookie.txt
exit
}
success() {
echo "Upload successfully done!"
cleanup
}
error() {
echo "Upload failed!"
cleanup
}
echo "Starting automatic upload..."
cd $WORKDIR || 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}" \
--compressed \
-c "bearingx_cookie.txt" \
--silent \
|| error
echo "Uploading file '${FILENAME}'"
responseCode=$(curl --write-out "%{http_code}\\n" "${PROTO-
COL}://${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}" \
--compressed \
-b "bearingx_cookie.txt" \
--output "/dev/null" \
--silent) \
|| error
# http response code should start with 20
if [[ "$responseCode" != 20* ]]
then
echo "Return code: ${responseCode}"
error
fi
success
How do the scripts work?
The following description is based on the supplied script 'automaticUploadBearingx.sh'. 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.
The shell script must have UNIX line endings in order to function correctly (the "-H [...]" commands have been moved to new lines for better readability).
moved to new lines for better readability, but still belong to the above command).