Forums

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

JUnit Zephyr Scale REST API Import Unsupported Media Type

Neelin Vakil April 13, 2022

I am currently trying to upload a JUnit xml document via the

https://api.zephyrscale.smartbear.com/v2/automations/executions/junit

endpoint and get back a 415 for Unsupported Media Type.

I am making the post request with the requests module using Python 3.8. I have tried passing the binary file contents in with the files argument or as part of the body, but both are returning the same error. I have tried both zip and xml files and have the content type set to application/json.

The documentation shows what the response looks like, but an example of the request would be greatly appreciated.

1 answer

0 votes
Neelin Vakil April 13, 2022

I was able to resolve the issue by fixing the header key value from the documentation.

Neelin Vakil April 13, 2022

I am currently able to upload the xml file by using the files parameter for the post function and having the body just contain the testCycle value, but the testCycle seems to be ignored.

Neelin Vakil April 13, 2022

Was able to resolve the issue by placing the file and testCycle keys in the files parameter and specifying the Content-Type for the testCycle portion.

Jonathan.Silver October 4, 2022

Neelin,

I am also having this same issue, but I'm not sure that I understand your resolution. 

The json body should be passed on the data= or the json= parm of the request? I've tried both. What did you specify for the body values: (id, utl, key)?

Body = json.dumps ( {
   "testCycle": {
         "id": 1,
         "url": "string",
         "key": "string"
       }
} )

They do not make any sense as this request creates a new execution and test cases 

thanks for posting!

Mahshad Dezhsetan
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 6, 2022

@Neelin Vakil 

Dear Neelin, I searched a lot and couldn't fix this problem, and still receive error 415!!

can you please kindly send me your request script? I would be grateful if you could help me fix this issue.

here is my email: mahshad.dezhsetan@gmail.com.

Jonathan.Silver November 11, 2022

I was also not able to resolve. I ended up calling curl (from python) to get around the problem.  Please also let me know if you are able to figure it out "the right way".

thanks,  jonathan.silver@terminix.com 

dieter
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!
June 5, 2023

Hi All,

Is it possible to share the code of how you fixed sollution? I can't seem to get around the 400 error. I used the documentation found here: https://support.smartbear.com/zephyr-scale-cloud/api-docs/#tag/Automations/operation/createJUnitExecutions

I've uploaded part of my code on how the request is build, any feedback would be highly appreciated. (It's Google Script)
Thank you,

D

 


  var headers = {
  "Authorization": "Bearer " + zephyrApiKey,
  "contentLength": bytes.length.toFixed(),
  }

var testCycle = {
"name":"Name of Testcycle folder",
"description" : null,
"jiraProjectVersion":null,
"folderId":8347322,
"customFields":{},
}

  var options = {
    "contentType":"multipart/form-data",
    "headers" : headers,
    "method" : "POST",
    "payload": {'file': bytes.toString(),
                'testCycle': Utilities.newBlob(JSON.stringify(testCycle),'application/json')
              },
    "muteHttpExceptions" : true
  };
  var request = UrlFetchApp.fetch(url, options);

dieter
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!
June 6, 2023

I got a working sollution for my Google App Ccript. I needed to:

  1. move the 'multipart/form-data' from options to the header
  2. pass the data as Google Script blob instead of byte array

I used following code and hope it can be of some inspiration.

Regards,

D



  var headers = {
  "Authorization": "Bearer " + zephyrApiKey,
  "contentType":"multipart/form-data",
  }

  var testCycle = {
  "name":"Name of Testcycle folder",
  "description" : null,
  "jiraProjectVersion":null,
  "folderId":8347322,
  "customFields":{},
  }

  var options = {
    "headers" : headers,
    "method" : "post",
    "payload": {"file": blob,
                "testCycle": Utilities.newBlob(JSON.stringify(testCycle).toString(),"application/json")
              },
    "muteHttpExceptions" : true
  };
  var request = UrlFetchApp.fetch(url, options);

Suggest an answer

Log in or Sign up to answer