added collect.sh

This commit is contained in:
Dominika 2020-09-19 18:32:46 +02:00
parent 093ed4b941
commit a33df2ee25

20
webroot/api/collect.shs Executable file
View file

@ -0,0 +1,20 @@
#!/bin/bash
if ! session_verify ${cookies[sh_session]}; then
exit 0
fi
source code/common.sh
data=$(curl -s -X POST -H "$(get_auth_string)" -H "Content-type: application/json" "https://api-inmobile-pl.easypack24.net/v1/collect/validate" --data '{"geoPoint":{"accuracy":"1","latitude":"'${get_data[lat]}'","longitude":"'${get_data[lon]}'"},"parcel":{"openCode":"'${get_data[openCode]}'","shipmentNumber":"'${get_data[id]}'"}}')
if [[ $(echo $data | jq .status) == "403" ]]; then
echo $data | jq "{status: .status, error: .error}"
else
uuid=$(echo $data | jq -r ".sessionUuid")
data=$(curl -X POST -H "Authorization: Bearer $(cat authToken)" "https://api-inmobile-pl.easypack24.net/v1/collect/compartment/open/$uuid")
if [[ $(echo $data | jq ".compartment") != "" ]]; then
echo $data
else
jq -n '{status: $ARGS.positional[0], error: $ARGS.positional[1]}' --args -1 "emptyPage"
fi
fi