ocw/webroot/api/collect.shs
2020-10-05 00:48:58 +02:00

21 lines
915 B
Bash
Executable file

#!/bin/bash
if ! session_verify ${cookies[sh_session]}; then
exit 0
fi
source "${cfg[namespace]}/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