Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,300,911
Community Members
 
Community Events
165
Community Groups

XRay - Import executions format

I am trying to follow the documentation found here: https://docs.getxray.app/display/XRAYCLOUD/Import+Execution+Results+-+REST+v2#ImportExecutionResultsRESTv2-XrayJSONresults 

I have tried many different combinations and I believe I am following the example, but all I ever receive is a 400 status code with:

{
"error": "Result is not valid Xray Format"
}

 

Example payloads:

ONE:

{
"info": {
"summary": "Angela test integration summary",
"description": "This is a test of sending stuff through xray API",
"version": "v1.3",
"user": "angela.robertson@choosemylo.com",
"revision": "1.0.42134",
"startDate": "2022-05-03T11:47:35+01:00",
"finishDate": "2022-05-03T11:52:35+01:00",
"testPlanKey": "EE-137",
"testEnvironments": ["iOS-Chrome", "Windows-Chrome"]
},
"tests": [
{
"testKey": "EE-2",
"start": "2022-05-03T11:47:35+01:00",
"finish": "2022-05-03T11:52:35+01:00",
"actualResult": "postman example",
"status": "PASSED"
}
]
}

TWO:

{
"info": {
"summary": "Angela test integration summary",
"description": "This is a test of sending stuff through xray API",
"user": "angela.robertson@choosemylo.com",
"testPlanKey": "EE-137"
},
"tests": [
{
"testKey": "EE-2",
"comment": "postman example",
"status": "PASSED"
},
{
"testKey": "EE-2",
"comment": "second run",
"steps": [
{
"comment": "Verify nav bar header when not maximized",
"status": "PASSED",
"actualResult": "some message"
}
]
}
]
}

 

1 answer

1 accepted

0 votes
Answer accepted
Stefan Salzl Community Leader May 05, 2022

Hi @Angela Robertson ,

I tried your JSON and worked on my side. Could you please also show your API call?

Best
Stefan

Ideally, I want to write Nodejs code from my Node Nightwatch repository to send the information in.  I am also trying to do this manually with PostMan to confirm that there is nothing wrong with my code so far.  

I'm going to show the PostMan screenshots first since they are a little more straightforward to look at.  Here a post of the import call:
PostMan-Result.PNG

I have only two headers set:  

PostMan-Headers.PNG

 

I am pretty sure the authorization is correct.  I call to get a token before making this subsequent post.  Without a token I'll see:

{"error":"Could not find authentication data on request"}

 

The same thing happens with my node code.  Here is everything you should need to duplicate (minus our client secrets):

const axios = require('axios').default
const { AxiosError } = require('axios')

const AUTH_URL = 'https://xray.cloud.getxray.app/api/v2/authenticate'
const IMPORT_URL = 'https://xray.cloud.getxray.app/api/v2/import/execution'

async function getToken () {
const tokenConfig = {
method: 'post',
url: AUTH_URL,
data: {
client_id: '<<redacted>>',
client_secret: '<<redacted>>'
}
}
const response = await axios.request(tokenConfig)
return response.data
}

async function postResults () {
const token = await getToken()
const importData = {
info: {
summary: 'Angela test integration summary',
description: 'This is a test of sending stuff through xray API',
testPlanKey: 'EE-137'
},
tests: [
{
testKey: 'EE-2',
start: '2022-05-03T11:47:35+01:00',
finish: '2022-05-03T11:52:35+01:00',
actualResult: 'postman example',
status: 'PASSED'
}
]
}
const importConfig = {
method: 'post',
url: IMPORT_URL,
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${ token }`
},
data: importData
}
const response = await axios.request(importConfig)
}

async function main () {
try {
await postResults()
} catch (err) {
console.log('ERROR:' + err)
if (err instanceof AxiosError) {
const { code, config, response } = err
const { status, data } = response
console.log('\n\nERROR DETAILS:', { code, config, status, data })
} else {
console.log('ERROR DETAILS', err.stacktrace)
}
}
}

main()

 

This is the output I get, which is the same as PostMan:

ERROR:AxiosError: Request failed with status code 400


ERROR DETAILS: {
code: 'ERR_BAD_REQUEST',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [Function: httpAdapter],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
env: { FormData: [Function] },
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
Authorization: 'Bearer <<redacted>>',
'User-Agent': 'axios/0.27.2',
'Content-Length': 295
},
method: 'post',
url: 'https://xray.cloud.getxray.app/api/v2/import/execution',
data: '{"info":{"summary":"Angela test integration summary","description":"This is a test of sending stuff through xray API","testPlanKey":"EE-137"},"tests":[{"testKey":"EE-2","start":"2022-05-03T11:47:35+01:00","finish":"2022-05-03T11:52:35+01:00","actualResult":"postman example","status":"PASSED"}]}'
},
status: 400,
data: { error: 'Result is not valid Xray Format' }
}
Like Stefan Salzl likes this
Stefan Salzl Community Leader May 05, 2022

Hi @Angela Robertson 

guess we´ve got the problem:

"tests": [
{
"testKey": "EE-2",
"start": "2022-05-03T11:47:35+01:00",
"finish": "2022-05-03T11:52:35+01:00",
"actualResult": "postman example",
"status": "PASSED"
}
]

actualResult refers to test-steps within the test-run. 

Obviously I did a copy paste error when I tried to process your json =S I tried that one now with "actualResult" within the "tests" section and got the same error. 

Could you please try without actualResult in the tests section? or if needed add a "steps" section and add required actualResult to the appropriate test step.

Hope this helps.

Best
Stefan 

Like Angela Robertson likes this

@Stefan Salzl Thank you.  I finally found the actual schema for the results (here ) and a schema validator, which gave me the same information.

I think this will get me what I need.  I did change that "actualResults" to a "comment" and it did import successfully.

Thank you again!

Stefan Salzl Community Leader May 06, 2022

@Angela Robertson 

Awesome. Great to know you got that working 💪🏼👍🏼

Please consider to hit the accept button in order to mark this as solved and makes it easier for other users to find solutions to similar problems.

Best
Stefan

Like Angela Robertson likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Marketplace Partner Spotlight: AppLiger

This month the spotlight is on AppLiger. We caught up with Pavel Pavlovsky, CEO and Product Manager, to learn how the company started and what fuels the team's creativity.    Atlassian:...

407 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you