Skip to content

Instantly share code, notes, and snippets.

@jweisman jweisman/finance.sh
Created May 2, 2019

Embed
What would you like to do?
Automating Alma API-based integration with ERP
#!/bin/sh
IFS=$'\n' # break on newline only
echo "Getting invoices ready for payment"
invoices=`curl -s --fail -H "Authorization: apikey $ALMA_APIKEY" -H "Accept: application/json" "https://api-na.hosted.exlibrisgroup.com/almaws/v1/acq/invoices?invoice_workflow_status=Waiting%20to%20be%20Sent&view=brief" | jq -c '.invoice | .[]'`;
for id in $invoices; do
echo "Marking invoice $(echo $id | jq -r '.number') as sent to ERP"
curl -s -o /dev/null -X POST -H "Authorization: apikey $ALMA_APIKEY" -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{}' "https://api-na.hosted.exlibrisgroup.com/almaws/v1/acq/invoices/$(echo $id | jq -r '.id')?op=mark_in_erp"
# Send invoice to ERP
# Receive response from ERP
echo "Marking invoice $(echo $id | jq -r '.number') as paid"
payment="{\"payment\":{\"voucher_date\":\"$(date +%F)\",\"voucher_amount\":$(echo $id | jq -r '.total_amount'),\"voucher_currency\":{\"value\":\"USD\"},\"voucher_number\":\"123-4\"}}"
curl -s -o /dev/null -X POST -H "Authorization: apikey $ALMA_APIKEY" -H 'Content-Type: application/json' -H 'Accept: application/json' -d $payment "https://api-na.hosted.exlibrisgroup.com/almaws/v1/acq/invoices/$(echo $id | jq -r '.id')?op=paid"
break; # only do one for testing
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.