This endpoint lets you upload a ZIP/TAR.GZ file with automated test results. Once the upload is successful, RTM creates a Test Execution issue with Test Case Executions for each test result.
Parameters | Description |
---|---|
projectKey (string, required) | The key of the RTM project used for importing the test results. |
file (file, required) | A ZIP/TAR.GZ file with the test results. Only ZIP/TAR.GZ files are supported, with a maximum size of 50 MB. |
reportType (string, required) | The format of the test results file. Accepted values are specific to the supported report types (e.g., JUNIT, NUNIT). |
jobUrl (string, required) | The URL of the CI job that executed the tests. It needs to start with http or https. |
name (string, optional) | A name used as summary for created Test Execution issue. |
treePath (string, optional) | A Folder path for created Test Execution. If path does not exists each folder will be created (e.g., /Automatic/e2e/moduleA). When empty then fallbacks to folder configured in RTM project configuration. |
testExecutionFields (string, optional) | A JSON string containing additional fields for the created Test Execution issue. Body compatible with the create issue REST API. |
testCaseFields (string, optional) | A JSON string containing additional fields for all created Test Cases issues. Body compatible with create issue REST API |
curl -X POST 'https://your-rtm-instance.com/api/v2/automation/import-test-results' \
-H 'Authorization: Bearer YOUR_API_TOKEN' \
-F 'projectKey=PROJECT_KEY' \
-F 'file=@/path/to/test-results.tar.gz' \
-F 'reportType=JUNIT' \
-F 'name=Example automated test execution'
-F 'treePath=/Automatic/e2e/moduleA'
-F 'jobUrl=https://ci.example.com/job/123' \
-F 'testExecutionFields={ "fields": {"labels" : ["e2etest"]} }' \
-F 'testCaseFields={"labels": ["automated", "regression"]}'
Access environment variables directly using process.env in Node.js without the dotenv package, as long as the environment variables are set before running the script.
Set environment variables when running your Node.js script:
RTM_API_TOKEN=your-api-token PROJECT_KEY=your-project-key RTM_URL=https://your-rtm-instance.com node script.js
If you’re using Node.js 20 or later, you can also use the –env-file flag to load variables from a .env file:
node --env-file=.env script.js
const fetch = require('node-fetch');
const FormData = require('form-data');
const fs = require('fs');
// Read environment variables
const RTM_API_TOKEN = process.env.RTM_API_TOKEN;
const PROJECT_KEY = process.env.PROJECT_KEY;
const RTM_URL = process.env.RTM_URL;
// Validate that required environment variables are set
if (!RTM_API_TOKEN || !PROJECT_KEY || !RTM_URL) {
console.error('Error: Missing required environment variables.');
process.exit(1);
}
// Create the FormData object
const form = new FormData();
form.append('projectKey', PROJECT_KEY);
form.append('file', fs.createReadStream('/path/to/test-results.tar.gz')); // Update with the actual path to your file
form.append('reportType', 'JUNIT');
form.append('jobUrl', 'https://ci.example.com/job/123');
form.append(
'testExecutionFields',
JSON.stringify({
fields: {
summary: 'Automated Test Execution',
description: 'Imported from CI',
},
})
);
form.append(
'testCaseFields',
JSON.stringify({
fields: {
labels: ['automated', 'regression'],
},
})
);
// Send the POST request using fetch
fetch(`${RTM_URL}/api/v2/automation/import-test-results`, {
method: 'POST',
headers: {
Authorization: `Bearer ${RTM_API_TOKEN}`, // Use the API token from environment variables
...form.getHeaders(), // Include headers from FormData
},
body: form, // Set the body to the FormData object
})
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status} - ${response.statusText}`);
}
return response.json(); // Parse the JSON response
})
.then((data) => {
console.log('Import Task ID:', data); // Log the response
})
.catch((error) => {
console.error('Error:', error.message);
});
If you’re using Node.js 20 or newer and want to load environment variables from a .env file:
RTM_API_TOKEN=your-api-token
PROJECT_KEY=your-project-key
RTM_URL=https://your-rtm-instance.com
node --env-file=.env script.js
If both an environment variable and a variable in the .env file have the same name, the environment variable takes precedence.
import requests
import time
# RTM API endpoint for importing test results
url = 'https://your-rtm-instance.com/api/v2/automation/import-test-results'
# Replace 'YOUR_API_TOKEN' with the API token you generated
headers = {
'Authorization': 'Bearer YOUR_API_TOKEN'
}
# (Optional) Test Execution Fields.
# This dictionary allows you to set custom fields for the Test Execution created in RTM.
# To use this, uncomment the 'test_execution_fields' variable and its usage in the 'data' dictionary below.
# Ensure the field ids and values are valid for your RTM project configuration, see Jira Cloud REST API for more examples.
# test_execution_fields = {
# "fields": {
# "summary": "Automated Test Execution",
# }
# }
# Path to the ZIP or TAR.GZ file containing test results XML files
test_results_archive_path = '/path/to/test-results.tar.gz' # Update with the actual path
# Open the ZIP file in binary read mode
with open(test_results_archive_path, 'rb') as f:
files = {
'file': f
}
data = {
'projectKey': 'PROJECT_KEY', # Replace with your actual project key
'reportType': 'JUNIT', # The format of the test results, use JUNIT or NUNIT
'jobUrl': 'https://ci.example.com/job/123', # URL to the CI job
# If using testExecutionFields, uncomment the line below:
# 'testExecutionFields': json.dumps(test_execution_fields), # Convert the dictionary to a JSON string
}
try:
# Send a POST request to the RTM API
response = requests.post(url, headers=headers, files=files, data=data)
response.raise_for_status() # Raise an exception for HTTP errors
# Print the import task ID returned by the API
task_id = response.text
print('Import Task ID:', task_id)
except requests.exceptions.RequestException as e:
print('Request failed:', e)
if response is not None:
print('Response Status Code:', response.status_code)
print('Response Text:', response.text)
except Exception as e:
# Catch any other unexpected errors.
print(f"An unexpected error occurred: {e}")
# Check import status result
import_status_url = f'https://your-rtm-instance.com/api/v2/automation/import-status/{task_id}'
while True:
import_status_response = requests.get(import_status_url, headers=headers)
import_status_response.raise_for_status() # Raise an exception for bad status codes
import_status = import_status_response.json()
print('Import Status:', import_status)
if import_status.get('status') != 'IMPORTING':
break # Exit the loop when the status is no longer 'IMPORTING'
time.sleep(3)
This endpoint lets you check the status of an import task using the task ID obtained from the initial import request.
Parameters | Description |
---|---|
taskId (UUID, required) | The unique identifier of the import task. |
curl -X GET 'https://your-rtm-instance.com/api/v2/automation/import-status/{taskId}' \
-H 'Authorization: Bearer YOUR_API_TOKEN'
const taskId = 'your-task-id'; // Replace with your actual task ID
const apiUrl = `https://your-rtm-instance.com/api/v2/automation/import-status/${taskId}`; // Update the base URL if necessary
fetch(apiUrl, {
method: 'GET',
headers: {
Authorization: 'Bearer YOUR_API_TOKEN', // Replace with your actual API token
},
})
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json(); // Parse the JSON response
})
.then((data) => {
console.log('Import Status:', data); // Log the response data
})
.catch((error) => {
console.error('Error:', error.message);
});
import requests
task_id = 'your-task-id'
url = f'https://your-rtm-instance.com/api/v2/automation/import-status/{task_id}'
headers = {
'Authorization': 'Bearer YOUR_API_TOKEN'
}
response = requests.get(url, headers=headers)
print('Import Status:', response.json())
If you can’t find the answer you need in our documentation, raise a support request. Include as much information as possible to help our support team resolve your issue faster.