Skip to content

Instantly share code, notes, and snippets.

@jweisman jweisman/export-set.sh
Last active Oct 18, 2017

Embed
What would you like to do?
Process Orchestration in Alma with the Job and Set APIs
#!/bin/bash
echo "Creating new set"
SET_ID=`curl -s --fail -X POST -H "Authorization: apikey $API_KEY" -H "Content-type: application/xml" -H "Accept: application/xml" --data @set.xml "https://api-na.hosted.exlibrisgroup.com/almaws/v1/conf/sets" | xmllint --xpath '/set/id/text()' -`
res=$?
if test $res != 0; then
echo "HTTP request failed with return code $res"
exit $res
fi
echo "Setting the job payload to use set $SET_ID"
python - <<-EOF
from xml.etree import ElementTree as et
tree = et.parse("job.xml")
tree.find("parameters/parameter[name='set_id']/value").text = "$SET_ID"
tree.write("job.xml")
EOF
echo "Submitting the export job"
JOB_INSTANCE_URL=`curl -s --fail -X POST -H "Authorization: apikey $API_KEY" -H "Content-type: application/xml" -H "Accept: application/xml" --data @job.xml "https://api-na.hosted.exlibrisgroup.com/almaws/v1/conf/jobs/M44?op=run" | xmllint --xpath 'string(/job/additional_info/@link)' -`
res=$?
if test $res != 0; then
echo "HTTP request failed with return code $res"
exit $res
fi
echo "Checking the job status at $JOB_INSTANCE_URL"
until [[ "$JOB_STATUS" == "COMPLETED"* ]]; do
sleep 3
curl -s --fail -H "Authorization: apikey $API_KEY" -H "Accept: application/xml" "$JOB_INSTANCE_URL" > job_instance.xml
JOB_PROGRESS=`xmllint --xpath '/job_instance/progress/text()' job_instance.xml`
JOB_STATUS=`xmllint --xpath '/job_instance/status/text()' job_instance.xml`
FILE_ID=`xmllint --xpath '/job_instance/counters/counter[type="c.jobs.bibExport.link"]/value/text()' job_instance.xml`
echo "Job progress: $JOB_PROGRESS; Job status: $JOB_STATUS"
done
if [ "$JOB_STATUS" = "COMPLETED_SUCCESS" ]; then
echo "Downloading the files for $FILE_ID"
lftp -c "connect sftp://$FTP_USER:$FTP_PASS@ftp.exlibrisgroup.com/public/TR_INTEGRATION_INST/export; mget *$FILE_ID*"
else
echo "Job not completed successfully. No files to download."
fi
echo "Deleting set $SET_ID"
curl -s --fail -X DELETE -H "Authorization: apikey $API_KEY" "https://api-na.hosted.exlibrisgroup.com/almaws/v1/conf/sets/$SET_ID"
echo "Done"
<job>
<parameters>
<parameter>
<name>task_ExportBibParams_outputFormat_string</name>
<value>MARC21_XML</value>
</parameter>
<parameter>
<name>task_ExportBibParams_outputRegistryFormat_string</name>
<value>3</value>
</parameter>
<parameter>
<name>task_ExportBibParams_maxSize_string</name>
<value>0</value>
</parameter>
<parameter>
<name>task_ExportBibParams_enrich_string</name>
<value>Null</value>
</parameter>
<parameter>
<name>task_ExportBibParams_exportFolder_string</name>
<value>PRIVATE</value>
</parameter>
<parameter>
<name>task_ExportParams_ftpConfig_string</name>
<value>85625670000561</value>
</parameter>
<parameter>
<name>task_ExportParams_ftpSubdirectory_string</name>
<value>export</value>
</parameter>
<parameter>
<name>set_id</name>
<value>2960292890000561</value>
</parameter>
<parameter>
<name>job_name</name>
<value>Export Bibliographic Records - via API - Export small test</value>
</parameter>
</parameters>
</job>
<set>
<name>Recent Binghamton Material</name>
<description></description>
<type desc="Logical">LOGICAL</type>
<content desc="All Titles">BIB_MMS</content>
<private desc="Yes">true</private>
<status desc="Active">ACTIVE</status>
<query>BIB_MMS where BIB_MMS (all CONTAIN "Binghamton" AND main_pub_date GREATER_EQUAL "2000")
</query>
</set>
@jweisman

This comment has been minimized.

Copy link
Owner Author

commented Sep 5, 2017

For more information on this Gist, see this blog post.

To run this script, set the following environment variables:

  • API_KEY: Key with read/write on the configuration APIs
  • FTP_USER and FTP_PASS: Username and password for the specified FTP configuration.
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.