#! /bin/bash #Check if I have enough parameters: if [ -z $2 ] then echo "Usage: $ ./fax.sh where has to be a german faxline number" exit 1 fi . authorization.sh #Prepare fax credentials: FILE=$1 echo -n "Sending file ${FILE} " REC=$(echo $2 | sed -e 's:[^+0-9]::g' -e 's:^0\([1-9]\):+49\1:') echo "to $REC" #Needs to be base64 encoded: CONTENT=$(base64 $FILE -w 0) if [ -z "$CONTENT" ]; then echo "Encoding failed" fi DATA='{"faxlineId":"f0", "recipient":"'${REC}'", "filename":"fax.pdf", "base64Content":"'${CONTENT}'"}' #Send fax FAXID=$(curl --request POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" --data "$DATA" "https://api.sipgate.com/v2/sessions/fax" -s | jq '.sessionId' | sed -e 's:"::g' ) if [ -z $FAXID ] then echo "Something went wrong, I didn't receive some fax id back." else echo "Sipgate took your fax as sessionID $FAXID" echo "$FAXID" >> .fax_history fi #Check if fax request was accepted by sipgate curl --request GET --header 'Content-Type: application/json' --header 'Accept: application/json' --header "Authorization: Bearer $AUTH_TOKEN" "https://api.sipgate.com/v2/history/$FAXID" -s | jq '.faxStatusType' #And show the account balance . getbalance.sh