Automate queries with cURL

When you need to run a saved Project Tracker query or report repeatedly, try packaging cURL commands in a shell script.

cURL is a command line tool for getting or sending files using URL syntax. It supports a range of common Internet protocols, such as HTTP, HTTPS, FTP, and FTPS. For more information about cURL, see the cURL project web site.
Note: To use this example code, you must have cURL installed locally. You will also need a working knowledge of Project Tracker, HTML, HTTP, and shell scripting.
  1. If you do not already have saved reports or queries that you wish to execute through a script, create them and record the URL for their output.
    1. Log into the project through the web interface.
    2. Create and save the queries and reports that you want your script to execute. The scope of the saved queries/reports should be "Personal."
    3. Configure the saved queries/reports so that the results are exported to a MS Excel or TSV file.
    4. Go to the appropriate page to see your saved query or report.
      • To get the URLs of saved queries, go to the Saved query list page.
      • To get the URLs of saved reports, go to the Saved report list page.
    5. Use your browser's "View page source" function to pull up the raw HTML source view of the page and locate the name of your query in the HTML source page.
      Note: The string follows the pattern <a href="[URL]">[query name]</a>. Copy only the [URL] portion of the string to use in your script. For example, suppose the query returns this URL:

      • The portion up to the question mark is your URL.
      • The portion from the question mark onward is used as an argument in the command.

      You will use these to build the command.

  2. Log into the domain with cURL.
    • curl -c cookies.txt -d 'loginID=[Login]&password=[password]&Login=Login' 'http://[domain]/servlets/Login?Button=Login'
    • If your site uses SSL, consider using the -k option, which suppresses certificate validation and allows cURL to connect to SSL sites without certificates. For help defining the commands for SSL-enabled sites, see the cURL user documentation.
    • The -k option to suppress certificate verification should only be used if you can verify the server's authenticity in some other way.
    • To convert your badge to pem, use this command:
      • openssl pkcs12 -in /director/folder/hp.p12 -clcertificates -out private.pem
    • When you log into the domain through a script, the login information is passed via URL. The username and password must conform to the rules for a URL: no unencoded spaces, underscores, or other prohibited punctuation. While special characters are not generally found in usernames, the domain may require that they be used in passwords. If the password uses special characters, it would need to be properly encoded.
    • Your password (marked here by [password]) will be visible to anyone who can see your scripts.
  3. Execute the saved query and save the response to the file you specify.
    • curl -b cookies.txt -d 'queryId=125&action=Search&eventSubmit_doRunstoredquery=Search&curmitlistid=140' 'http://[project name].[domainname]/servlets/Scarab/remcurreport/true/template/IssueList.vm'>[query].xls
  4. Execute a saved report and save the response to the file you specify.
    • curl -b cookies.txt -d 'report_id=100&eventsubmit_dogeneratereport=foo&action=ConfigureReport' 'http://[project name].[domain name]/servlets/Scarab/template/reports%2CReportList.vm'>[report].xls
Related questions
What operators does the Project Tracker search tool take?
Can I query more than one project at the same time?
What should a data export script look like?
Related actions
Automate queries with wget
Run an advanced query
Automate exports with wget
More information
More information about wget
More information about cURL