gurock / testrail-api

TestRail API: Examples on how to use TestRail's API from various languages
Other
116 stars 86 forks source link

{"error"=>"Field :suite_id is a required field."} #27

Closed wowza-mccarthy closed 4 years ago

wowza-mccarthy commented 4 years ago

Hello, I'm trying to write some Ruby bindings that can create a test run after through the Testrail API.

I keep running into this error:

{"error"=>"Field :suite_id is a required field."}

I have been providing the suite_id, but I'm wondering it it's in the wrong format. My method looks like:

    def add_new_run(path, options = {})
        body = {"suite_id": 632,
                    "name": "Automation run: TEST"}

        options = request_options.merge(options, body)      
        url = "#{base_uri}#{path}"    
        self.class.post(url, options)
    end

The resulting total options before making that POST call looks like (email and password obviously removed):

{:headers=>{"Accept"=>"application/json", "Content-Type"=>"application/json"},
 :basic_auth=>{:username=>"email", :password=>"password"},
 :suite_id=>632,
 :name=>"Automation run: #test"}

Does that look correct? Should it be wrapped in a :body =>? I've tried that as well, to no avail.

Let me know any ideas. Thanks!

jonrgurock commented 4 years ago

Hi @wowza-mccarthy ,

I'm happy to help! Based on the error message, this would likely indicate the body of the API request is not formatted properly. TestRail's API bindings for Ruby use the net/http or net/https libraries to make API requests.

The code snippets you provided do not indicate the specific libraries or code you are using to make and format your API request.

We would usually recommend using the bindings provided or modifying these to suit your needs as our support team may not be familiar with other libraries and modules.

That being said, I was able to successfully add a test run to a project using Ruby and TestRail's API bindings. For this, I used the following code:

require './testrail'

client = TestRail::APIClient.new('XXXXX')
client.user = 'XXXX'
client.password = 'XXXXX'

project_id = 11
body = { 'suite_id': 53, "name": "Hello World"}
z = client.send_post("add_run/#{project_id}", body)
puts z

Inside the bindings, I added a debug line at line 103: puts request.body

This provided the output of {:suite_id=>53, :name=>"Hello World"}

The body of your API request should be similar to the above. Comparing this to your output, it appears the body of your request may not be in JSON format, are you using JSON.dump(body) to assign your POST data to your request's body?

I hope this is helpful and points you in the right direction. If you need further assistance with this, please email our support team at contact@gurock.com and provide us with the full code for your request (removing your credentials, obviously).

Regards, Jon