Skip to content

Instantly share code, notes, and snippets.

@ojacques
Last active October 29, 2020 12:28
Show Gist options
  • Save ojacques/c86001cf490a66f60dc62307b05af841 to your computer and use it in GitHub Desktop.
Save ojacques/c86001cf490a66f60dc62307b05af841 to your computer and use it in GitHub Desktop.
ALM REST API with curl

This GIST shows example on how to authenticate with HP/HPE/Microfocus ALM REST API and run queries.

Note:

By default, the ALM REST API returns XML data. If you want to get JSON data, add -H "Accept: application/json"

Authenticate with ALM and set the LWSSO_COOKIE_KEY cookie

curl -X POST -H "Content-Type: text/xml" --cookie cookies.txt -k --cookie-jar cookies.txt -d "alm_useralm_password" https://alm_host:8443/qcbin/authentication-point/alm-authenticate

Alternatively (same result):

curl --cookie cookies.txt --cookie-jar cookies.txt --user alm_user:alm_password https://alm_host:8443/qcbin/authentication-point/authenticate

Setup QCSession cookie (need with ALM >= 12.x)

curl -X POST --cookie cookies.txt --cookie-jar cookies.txt https://alm_host:8443/qcbin/rest/site-session

Get defects assigned to an individual

curl --cookie cookies.txt --cookie-jar cookies.txt -g "https://alm_host:8443/qcbin/rest/domains/[ALM_DOMAIN]/projects/[ALM_PROJECT]/defects?fields=id,name,status,severity,owner&query={owner['alm_user']}"

Get opened defects with a custom field (user-template-35=205713 in this example) as filter

curl --cookie cookies.txt --cookie-jar cookies.txt -g "https://alm_host:8443/qcbin/rest/domains/IT/projects/WORKSPACE_2/defects?fields=id,name,status,severity,owner&query={user-template-35['205713*'];status[Not%20Closed]}"

Get the list of all fields you can filter on by querying all fields of a particular command

curl --cookie cookies.txt --cookie-jar cookies.txt -g "https://alm_host:8443/qcbin/rest/domains/IT/projects/WORKSPACE_2/defects/14729"

Logout when you are done (or keep re-using the cookie and disconnect only at the end of the session)

curl --cookie cookies.txt -k --cookie-jar cookies.txt https://alm_host:8443/qcbin/authentication-point/logout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment