Skip to content

Instantly share code, notes, and snippets.

@jweisman
Created May 2, 2019 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jweisman/e1969a2236a1056f92a18179c4382f72 to your computer and use it in GitHub Desktop.
Save jweisman/e1969a2236a1056f92a18179c4382f72 to your computer and use it in GitHub Desktop.
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