ocw/webroot/api/collect.shs

27 lines
1.0 KiB
Bash

#!/bin/bash
if ! silent=yes source "${cfg[namespace]}/webroot/api/session.shs"; then
return
fi
source "${cfg[namespace]}/code/common.sh"
data=''
while [[ "$data" == '' ]]; do
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":"'"${post_data[lat]}"'","longitude":"'"${post_data[lon]}"'"},"parcel":{"openCode":"'"${post_data[openCode]}"'","shipmentNumber":"'"${post_data[id]}"'"}}')
done
if [[ $(echo $data | jq .status) == "403" ]]; then
echo $data | jq "{status: .status, msg: .error}"
else
uuid=$(echo $data | jq -r ".sessionUuid")
data=''
while [[ "$data" == '' ]]; do
data=$(curl -X POST -H "$(get_auth_string)" "https://api-inmobile-pl.easypack24.net/v1/collect/compartment/open/$uuid")
done
if [[ $(echo $data | jq ".compartment") != "" ]]; then
echo $data
else
jq -n '{status: $ARGS.positional[0], msg: $ARGS.positional[1]}' --args -1 "OCW received an invalid response from the API."
fi
fi