Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Attachments to Test Step via API in XRAY on JIRA Server

Edwin Saji Uthuppan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 11, 2022

Hi everyone.

I am using Xray on a an instance of JIRA server. I would like to use the REST API to add an attachment to an XRAY Test step.

 

Piecing together information from different sources (source1 , source2 , source3 ) , I have settled on the following request:

URL = https://{jira server}/rest/raven/2.0/api/test/{testKey}/steps/{testId}

HTTPRequest = PUT

Body = {
"attachments": {
"add":[
{
"data":"MTAwIHJwbQ0KMjAwIHJwbQ0KMzAwIHJwbQ==",
"filename":"speed points.txt",
"contentType": "text/plain",
}
]
}
}

But that gives the following response

 

400 

{'error': 'Step fields must be provided to create a new test step'}

 

So then I tried the following request:

 URL = https://{jira server}/rest/raven/2.0/api/test/{testKey}/steps/{testId}

HTTPRequest = PUT

Body = {
"fields":{
"Action":"Testing"
},

"attachments": {
"add":[
{
"data":"MTAwIHJwbQ0KMjAwIHJwbQ0KMzAwIHJwbQ==",
"filename":"speed points.txt",
"contentType": "text/plain"
}
]
}
}

which gives the following response:

200 

{'step': {'id': 270216, 'attachmentIds': []}, 'warnings': ['Error creating attachment.']}

 

And just as the response describes, the action field is updated, but no attachment was created!

 

Can someone help me with creating an attachment through scripts in XRAY Server?

Right now I am trying to maybe see if it is possible to make the same requests in a script the web page makes when creating an attachment. I haven't yet fully explored this option!

2 answers

1 vote
Tsega Tsahai
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 12, 2022

Hello, I was just having the same issue and I fixed it by editing the file name in the attachment block. For example:

 

"attachments": {
"add":[
{
"data":"MTAwIHJwbQ0KMjAwIHJwbQ0KMzAwIHJwbQ==",
"filename":"speed_points.txt",
"contentType": "text/plain"
}
]

 As it can be seen, I added an underscore in the file name to eliminate spaces. This was the solution that worked for me when I had the same issue. Hope this helps :)

Srinivas Ch October 27, 2022

how to did you get the data filed value?

Tsega Tsahai
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 29, 2022

I opened the text file and then encoded the contents to base64 using Python. 

Srinivas Ch October 29, 2022

Is it possible to use vbscript. Can you send me the code of python how you did it?

chakka.srinivas86@gmail.com

0 votes
Stefan Salzl
Community Champion
March 15, 2022

Hi @Edwin Saji Uthuppan and welcome to the community,

as far as I got XRAY documentation right the API doesn´t offer functionality to add attachment to test steps:

https://docs.getxray.app/display/XRAY/Test+Steps+-+REST

 

Best
Stefan

Edwin Saji Uthuppan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 15, 2022

Hi @Stefan Salzl 

Thanks for the reply!

image.png

 

Look at the above section: It looks like it supports addition of attachments.

There are two issues though, the request has been incorrectly marked as POST instead of PUT and additionally the fact that it doesn't actually work! If you look at the response messages i am getting it doesn't look like there is an issue in recognising my request, but there is an issue in processing my request. 

I will try to contact Xpand-IT, but i have to go through a lot of bureaucracy at my company... which is taking time XD

Stefan Salzl
Community Champion
March 15, 2022

I found the docu correctly as PUT:

BA08DEA5-8DAB-4CB6-AEC6-118E4B78F324.jpeg

What I could imagine (especially regarding the error message from your PUT approach) that the JSON array of the attachment is empty before and therefore cannot be „updated“. To check this:

could you try to run the PUT call on a test step that alteady has an attachment?

Best
Stefan

Srinivas Ch October 18, 2022

Hi All,

Giving File name is fine. How to provide the path and what format need to give?

I have added in request as "filePath": "C:/Srinivas"

Getting error as "Erro instantiating bean. Filed(s) evidences ->add->filePath do not follow the correct format.

Stefan Salzl
Community Champion
October 19, 2022

@Srinivas Ch -- welcome to the community,

I´m not sure if the api request accepts a "filePath" option/property. did you try to use the whole path of the file in your "fileName"?

 

"attachments": {
"add":[
{
"data":"whatever",
"filename":"C:\andyDirectory\filename.txt",
"contentType": "text/plain"
}
]

 

Best
Stefan

Srinivas Ch October 19, 2022

Getting response like Error creating attachment.

Given "filename":"C:/Srinivas/Test.txt"

 

Note: If I give syntax like "C:\Srinivas\Test.txt" it's not accepting

Stefan Salzl
Community Champion
October 19, 2022

Could you please provide all details to make it possible for the community to investigate into the situation?

What does your call look like exactly? What exactly is the outpout/response? etc.  --> everything that could help to analyze your problem.

Thanks in advance.

Best
Stefan

Srinivas Ch October 27, 2022

Can we add evidence for the test under test execution.

Evidence can be either html/txt file.

If yes what count be End point,

Body for the same?

Srinivas Ch October 27, 2022

 

Method : POST

url: jiraserver/rest/raven/1.0/import/execution

what to provide in data field. in documentation it shows some random alphanumeric values

Requeust Body.jpg

Suggest an answer

Log in or Sign up to answer