Create Mantis Issue using API [ Updated 2024 ]
Create Mantis Issue using API
Earlier, we looked at reporting an issue using the Mantis Web Interface. In this tutorial, we will learn to create an issue using the Mantis Rest API. This approach is useful in Automation. When a test case fails during an automation run, we can automatically create a bug in Automation using this call.
Create an Issue using Mantis Web Interface.
Postman API Tool
Let’s get started. We will use the Postman API tool to invoke the Rest API call manually. In case you you are new to the Postman tool:
Postman Tool: https://www.testingdocs.com/postman-api-tool/
How to execute an API call:
https://www.testingdocs.com/how-to-execute-rest-api-call-using-postman/
Headers
The API call uses the POST HTTP method. The Post method should have a request body. The content of the body is specified using the ‘Content-Type‘ HTTP request header. We will use the JSON content type for the API call. To specify we will set the Content-Type request header to ‘application/json‘.
Another header in the call is the Authorization header. The value of the header is the API token of the API caller. Follow this link to get an API token for your Mantis instance:
https://www.testingdocs.com/create-api-token-in-mantisbt/
API Request Body
The request body is the JSON string. It contains the details of the issue that you want to create like the bug summary, bug description, project name, etc.
Sample API Request JSON
Issue with minimal details:
{ "summary": "[TestingDocs.com] This issue is created using POST /issues REST API call", "description": "This is a sample test bug API Description - ", "category": { "name": "General" }, "project": { "name": "TestingDocsProject" } }
API Response
To execute the call click on the Send button. A successful API response status should be 201 created. Any other status code means that there is an issue with the call, server and the environment.
Sample API HTTP Response for the call:
{ "issue": { "id": 4, "summary": "[TestingDocs.com] This issue is created using POST /issues REST API call", "description": "This is a sample test bug API Description - ", "project": { "id": 1, "name": "TestingDocsProject" }, "category": { "id": 1, "name": "General" }, "reporter": { "id": 1, "name": "administrator", "email": "root@localhost" }, "status": { "id": 10, "name": "new", "label": "new", "color": "#fcbdbd" }, "resolution": { "id": 10, "name": "open", "label": "open" }, "view_state": { "id": 10, "name": "public", "label": "public" }, "priority": { "id": 30, "name": "normal", "label": "normal" }, "severity": { "id": 50, "name": "minor", "label": "minor" }, "reproducibility": { "id": 70, "name": "have not tried", "label": "have not tried" }, "sticky": false, "created_at": "2019-07-17T10:48:09+00:00", "updated_at": "2019-07-17T10:48:09+00:00", "history": [ { "created_at": "2019-07-17T10:48:09+00:00", "user": { "id": 1, "name": "administrator", "email": "root@localhost" }, "type": { "id": 1, "name": "issue-new" }, "message": "New Issue" } ] } }
We can notice the Bug id created is 4. The bug is created with minor severity and normal priority.
Verification
Log in to the Mantis Web interface and verify with the Bug id from the API response.
Rest API Automation
Automate POST call with Karate
Mantis Bug Tracker Tutorial