title: How to add a test run to ALM using REST API
body: <p>I searched high and low trying to figure out how to create a test run using the REST API for ALM. </p>
  
  <p>If anyone has found a better way then I would love to see it! </p>
  
  <p>Just figured this out last night.</p>
  
  <p>I used the tool called Postman to figure this out.</p>
  
  <p>This is how to get your testcycl-id via the REST API.  First go to the Test Lab page and create a test set and then add a test case (or multiple test cases) to it.  In the execution grid you can add the columns for "Test ID" and "ID".</p>
  
  <p>Test ID = test-id</p>
  
  <p>ID = test-config-id</p>
  
  <p>Next to the Execution Grid there is another button called, "Details".  If you click that you can find the Test Set ID.</p>
  
  <p>Test Set ID = cycle-id</p>
  
  <p>Once you have the cycle-id and the test-id you can perform a GET and pull out the whole record for  your test set that will include the testcycl-id.</p>
  
  <p>GET <a href="https://SERVER/qcbin/rest/domains/DOMAIN/projects/PROJECT/test-instances?query=" rel="nofollow">https://SERVER/qcbin/rest/domains/DOMAIN/projects/PROJECT/test-instances?query=</a>{cycle-id[123];test-id[4567]}</p>
  
  <p>Once you have this information you'll get back an xml with all the test instance details including the testcycl-id though in the xml it's called simply, "id". </p>
  
  <p>You can then use that for creating a test run that both creates a test run on the Test Runs page and also updates a test case in a test set in the Test Lab page.</p>
  
  <p>POST <a href="https://SERVER/qcbin/rest/domains/DOMAIN/projects/PROJECT/runs" rel="nofollow">https://SERVER/qcbin/rest/domains/DOMAIN/projects/PROJECT/runs</a></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;Entity Type="run"&gt;
  &lt;Fields&gt;
  &lt;Field Name="test-config-id"&gt;&lt;Value&gt;8901&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="cycle-id"&gt;&lt;Value&gt;123&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="test-id"&gt;&lt;Value&gt;4567&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="testcycl-id"&gt;&lt;Value&gt;THIS IS THE VALUE THAT YOU RAN THE GET TO FIND&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="build-revision"&gt;&lt;Value&gt;1&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="name"&gt;&lt;Value&gt;MyRun&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="owner"&gt;&lt;Value&gt;johnsmith&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="status"&gt;&lt;Value&gt;Passed&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="subtype-id"&gt;&lt;Value&gt;hp.qc.run.external-test&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="duration"&gt;&lt;Value&gt;5&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="execution-date"&gt;&lt;Value&gt;2016-09-23&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="execution-time"&gt;&lt;Value&gt;08:01:07&lt;/Value&gt;&lt;/Field&gt;
  &lt;Field Name="status"&gt;&lt;Value&gt;Passed&lt;/Value&gt;&lt;/Field&gt;
  &lt;/Fields&gt;
  &lt;/Entity&gt;
  </code></pre>
  
  <p>Best of luck to those of you that are looking for this!</p>