Following this guide from Sergio found in stackoverflow I managed to get the simple upload version to work, but since we have mandatory fields such as "Components" it won't work.
I tried changing parts of the script following the xray documentation, but I just get 500 Internal Application Error when trying to run the script.
upload.py
import requests
import json
xray_cloud_base_url = "https://xray.cloud.xpand-it.com/api/v2"
client_id = "<my_id>"
client_secret = "<my_secret>"
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
auth_data = { "client_id": client_id, "client_secret": client_secret }
response = requests.post(f'{xray_cloud_base_url}/authenticate', data=json.dumps(auth_data), headers=headers)
auth_token = response.json()
files = {
"info": ("issueFields.json", open("issueFields.json","rb")),
"testInfo": ("testIssueFields.json", open("testIssueFields.json","rb")),
"results": ("output.xml", open("results/output.xml","rb"))
}
headers = {'Authorization': 'Bearer ' + auth_token, 'Content-Type': 'multipart/form-data'}
response = requests.post(f'{xray_cloud_base_url}/import/execution/robot/multipart', headers=headers, files=files)
print(response.status_code)
print(response.content)
500
b'{"error":"Internal Application Error!"}'
Got it to work by just simply removing the 'Content-Type': 'multipart/form-data' from the last post request header, it seems python requests fills that information itself if posting a dictionary of multiple files, and giving it multiple times breaks something. :)
when you have mandatory fields, it is necessary to use the multipart endpoint.
With the multipart endpoint, you can add additional JSON files with the values for the mandatory fields, so they can be set up with the values from those files.
Please check the multipart endpoint and examples here: https://docs.getxray.app/display/XRAY/Import+Execution+Results+-+REST#ImportExecutionResultsREST-RobotFrameworkXMLresultsMultipart
Thank you.
Kind regards,
Rogério Paiva [Xray Support Team]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Rogério Paiva - Xray Xporter
If you read my message you can see that I also linked the exact same documentation with examples on my message (except my link is for the xray cloud which my project is using and so the api url is different), so I have already gone through it. I'm using 2 json files, slightly modified from the example to fit my project, so I doubt that's the issue and maybe it's with the python script I posted on my message?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Probably it is an issue in the python code, however, I am not a python expert so unfortunately, I cannot help you there.
What I would advise, is to first try the command line with your files:
curl -H "Content-Type: multipart/form-data" -X POST -F info=@issueFields.json -F results=@results.xml -F testInfo=@testIssueFields.json -H "Authorization: Bearer $token" https://xray.cloud.getxray.app/api/v2/import/execution/robot/multipart
to ensure that your files are correct, and there isn't an issue with them.
After that, try to mimic the same request that the curl command sends using python code.
I hope this helps.
Thank you.
Kind regards,
Rogério Paiva [Xray Support Team]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I already figured out the issue and added the answer to this post earlier. Thank you anyway. :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.