Skip to content

Instantly share code, notes, and snippets.

@ojacques
Last active July 22, 2021 11:43
Show Gist options
  • Save ojacques/18bf69b5fb8e43b5495d9b148b3319c3 to your computer and use it in GitHub Desktop.
Save ojacques/18bf69b5fb8e43b5495d9b148b3319c3 to your computer and use it in GitHub Desktop.
ALM REST API usage with curl

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

SSL certificate verification

curl uses the file "ca-bundle.crt" by default and will get client certificates from that file. This is needed to avoid to use the "-k" unsecure switch in curl. Append the content of the ca-bundle.crt in this GIST to the rest of the ca-bundle.crt file, as provided by curl out of the box.

JSON or XML

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-authentication><user>alm_user</user><password>alm_password</password></alm-authentication>" 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 for a given EPR ID (user-template-35=205713 in this example) (IT Domain)

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