Database foreign key violation error via REST API

Monday, January 14, 2019
Avatar

When using the REST API to create a Test Case in a Project, I get back a general 400 Bad Request error with the message "The server encountered an error processing the request. The exception message is 'Database foreign key violation occurred'. See server logs for more details" in the response body, followed by some information about an exception stack trace

The JSON I'm supplying in the body of the POST request is:

{"Name":"This is a the Test Case",
"TestCaseStatusId":0,
"TestCaseTypeId":0}

I've also tried supplying the Name field only, and get the same error.

If I use the web interface to create a Test Case, I have no problems using the REST API to GET its ID number and then using POST to create Steps inside it, so I can't see what is stopping me from creating Test Cases.

6 Replies
Wednesday, January 16, 2019
Avatar
re: dbakkers Monday, January 14, 2019

Hello,

Most likely you need to pass additional information required by the API.

There is no such test case status as ID = 0 or type = 0, that is probably causing the issue right there.

Regards

Adam

Wednesday, January 16, 2019
Avatar
re: inflectra.david Wednesday, January 16, 2019

Hello Adam

The SpiraTeam REST API 5.0 reference page for Test Cases says those two properties definitely exist and you definitely can pass the value 0:

"TestCaseTypeId  - The type of test case, pass 0 to use the default value"

"TestCaseStatusId  - The status of the test case, pass 0 to use the default value"

 

That documentation page also says "Creates a new test case in the system. Name, TestCaseStatusId, and TestCaseTypeId are required fields." and even demonstrates the usage of those two fields in the JSON sample.

 

Also, as I said, even if I pass only the Name property, I still get the error.  If a required property is not passed in the request body, the API will normally send back a message advising which property has been omitted. So why in this case doesn't it tell me what I've omitted?

Can you be more specific and tell me what 'additional information' is required by the API, as all the criteria specified on the API documentation page seems to have been met. Alternatively, please post a sample JSON formatted body request that you've tested and works.

Wednesday, January 16, 2019
Avatar
re: inflectra.david Wednesday, January 16, 2019

Hello Adam

I've just made a minor breakthrough.

I tried submitting the request to the SpiraTeam v4 REST API as per this V4 REST API documentation page, and using just the Name field only, and it worked.... the Test Case was created.

When I inspect the Test Cases via the web interface, the Status shows as 'Obsolete' and the Type as 'Functional', but all else is fine.

So, it seems like the v5 REST API has a bug or the documentation page is incorrect.

Wednesday, January 16, 2019
Avatar
re: dbakkers Wednesday, January 16, 2019

Hello Adam

I've just done some further tests and can use the v5 API to create a Project, then create a Test Case Folder. I then switch to the v4 REST API and create the Test Case. I then switch back to the v5 API and create the Test Steps within that Test Case.

This works around the bug in the v5 API for the Test Cases, but there is a limit of the v4 API in that it doesn't support the creation Test Cases inside Test Case Folders. Bummer!

Please let me know when your developers have had a closer look into the v5 bug that affecting the creation of Test Cases.

Wednesday, January 16, 2019
Avatar
re: inflectra.david Wednesday, January 16, 2019

I've noticed that the v4 API does support creating Test Cases inside a Folder, the URL just needs to be different. So, I now have a full workaround for the v5 API bug until it can be resolved.

Wednesday, January 30, 2019
Avatar
re: dbakkers Wednesday, January 16, 2019

For anyone reading this thread, the issue turned out to be the API documentation, which says that the two fields TestCaseStatusId and TestCaseTypeId can be set to a value of 0.

Those fields need to be set to a value of 1, or higher, where the number correlates to the position of the required value in the drop-down selection on the web interface, as per this example for the Status of a Test Case:

Drop down selection

Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885

 

Statistics
  • Started: Monday, January 14, 2019
  • Last Reply: Wednesday, January 30, 2019
  • Replies: 6
  • Views: 7971