How to import Results using REST APIs?

Working Sample

Please look at Sample projects and Code snippets sections for a more concrete end-to-end example.

1. Use API Key for Importing Results

Please Generate API Key if you don't have for your selected project. 

2. Import test results

Import process is divided into 2 parts. 

  1. Get Upload file URL 
  2. Upload your test result file to generated URL

2.1 Get Upload file URL 

URL : {{JIRA Base URL}}/rest/qtm/latest/automation/importresults

Method : POST

Notes

  • zip file must contain files of same format given in the 'format' param.
  • Request must be contains form-data, json raw body payload is not supported.


Authorization

This Automation REST API is protected by the same restrictions which are provided via JIRA. This means that you need to log in in JIRA to access this API.

To supply basic Auth header, you need to perform the following steps:

1. Build a string of the form username:password

2. Base64 encode the string Encode

3. Supply an "Authorization" header with content "Basic " followed by the encoded string. For example, the string "fred:fred" encodes to "ZnJlZDpmcmVk" in base64, so you would make the request as follows.

 Authorization:  Basic ZnJlZDpmcmVk
		

Request Parameters

ParameterTypeRequiredDescription
apiKeystringYesYour API Key. API Key is unique for a specific user in a single project. The result will be imported for the project associated with the given API Key.
formatstringYes

Format of result file to be imported. Supported formats:

 

testAssetHierarchystringNo

Level of Hierarchy : Test Scenario-Test Case Or Test Case-Test Step

testCaseUpdateLevelnumberNoTest Case update level while reusing test case, starts from 0 to 2. (This is only applicable when you use TestCase-TestStep Hierarchy option)

0 Append test steps while reusing Test Case.
1 Override test steps while reusing Test Case.
2 No change in test steps while reusing Test Case.
Default :- No change in test steps while reusing Test Case.

testRunNamestringNoName of the test run to be created. Default value: Test Run
platformstringNoName of Platform on which test run to be executed.
labelsstringNoComma separated names of Labels to be added to the test run.
versionsstringNoComma separated names of versions to be added to the test run.
componentsstringNoComma separated names of Components to be added to the test run.
sprintstringNoName of Sprint to be added to the test run.
commentstringNoComment to be added to the test run.
testRunKeystringNoProvide Test Run key to append new results to existing Test Run.
attachFile
booleanNoPass true for attachments upload in execution. Default value: false.
JIRAFieldsJSONNoCheck specific Automation custom fields possible value and format here.


Responses

Response
Description

Pass

Returned if results file is uploaded successfully. The import process might take a while and you would be notified (by email or checking the status of the created test run) once the process completed.

Example

{
  "testRunURL": "{{JIRA Base URL}}/browse/JQ-1", 
"testRunKey":
"JQ-1"
  
}


  
Fail

                                  

Returned if any validation fails

Example

{
"error": {
"errorMessage": "apiKey field is required",
"errorCode": 404
},
"success": false
}

Produces

  • application/json

3. View imported test results

Please refer to View Imported Test Results section to view imported test results.


4. JIRA Fields


i) How to get Custom Field ID?

Rest call to JIRA to get all JIRA fields.

The following URL gives all custom fields get ID for selected custom fields that you want to apply.

<Jira_Base_URL>/rest/api/2/field 


ii) Base format for custom fields.

[
  {
    "testRun": [
      {
      }
    ]
  },
  {
    "testScenario": [
      {
      }
    ]
  },
  {
    "testCase": [
      {
      }
    ]
  }
]


iii) Standard Custom Field Types

The following types are for reference only, other types of Custom Field Types are also supported.


Custom Field Type
Validation Rule
Example
CheckboxesThe checkbox accepts comma separated multiple values{
  "customfield_10200": [
    {
      "value": "true"
    },
    {
      "value": "false"
    }
  ]
}
Date PickerThe Date picker accepts only specified format Date{
  "customfield_10202":"2017-09-06"
}
Date Time PickerThe Date time picker accepts only specified format Date and time{
  "customfield_10203": "2013-03-01T00:00:00.000+0400"
}
Number FieldThe Number field accepts any number with decimal{
  "customfield_10205": 2876784
}
Radio ButtonsThe radio button accepts single value from JIRA fields{
  "customfield_10206": {
    "value": "option1"
  }
}
Select List (multiple choices)The Select List Multiple accepts comma separated multiple values{
  "customfield_10208": [
    {
      "value": "Select List Multiple 1"
    },
    {
      "value": "Select List Multiple 2"
    }
  ]
}
Select List (single choice)The radio button accepts single value from JIRA fields{
  "customfield_10209": {
    "value": "Select List single 1"
  }
}
Text Field (multi-line)It accepts text in multiple lines{
  "customfield_10210": "this is sample.\nexample"
}
Text Field (single line)It accepts text in single line{
  "customfield_10211": "this is sample.example"
}
URL FieldIt accepts Web URL{
  "customfield_10212": "http://www.url-encode-decode.com/"
}
User Picker (single user)The User field accepts only available JIRA users{
  "customfield_10213": {
    "name": "admin"
  }
}


iv) JSON Example

If you want to set 2 custom fields (checkbox, single text) on test run issue type and one custom fields (Radio Button) on scenario and test case level.

"JIRAFields":
[
  {
    "testRun": [
      {
        "customfield_10200": [
          {
            "value": "true"
          },
          {
            "value": "false"
          }
        ]
      },
      {
        "customfield_10211": "this is sample.example"
      }
    ]
  },
  {
    "testScenario": [
      {
        "customfield_10206": {
          "value": "option1"
        }
      }
    ]
  },
  {
    "testCase": [
      {
        "customfield_10206": {
          "value": "option1"
        }
      }
    ]
  }
]