The minimum required information to add an issue via API are:
- project id (number)
- summary (the title of the issue; string)
- issueTypeId (number)
- priorityId (number)
These are documented under Form Parameters in the Add Issues documentation.
In order to get the required info, we can use the requests below.
To get project id:
Send GET request to URL:
https://[space id].backlog.com/api/v2/projects/[project key]?apiKey=[your API key]
Example:
https://xx.backlog.com/api/v2/projects/COMDEMO?apiKey=abcdefghijklmn
The JSON response would be like:
{
"id":33368,
"projectKey":"COMDEMO",
"name":"ComDemo",
"chartEnabled":true,
"subtaskingEnabled":true,
"projectLeaderCanEditProjectLeader":true,
"useWikiTreeView":true,
"textFormattingRule":"markdown",
"archived":false,
"displayOrder":2147483646,
"useDevAttributes":true
}
So the project id will be 33368. Which we will use later to send the request to add issues in the project.
To get list of issue types from the project:
Send GET request to URL:
https://[space id].backlog.com/api/v2/projects/[project id or key]/issueTypes?apiKey=[your API key]
Example:
https://xx.backlog.com/api/v2/projects/COMDEMO/issueTypes?apiKey=abcdefghijklmn
This will return a JSON response containing a list (i.e. array) of issue types of the project:
[
{"id":140151,"projectId":33368,"name":"Task","color":"#7ea800","displayOrder":0,"templateSummary":null,"templateDescription":null},
{"id":140150,"projectId":33368,"name":"Bug","color":"#990000","displayOrder":1,"templateSummary":null,"templateDescription":null},
{"id":140152,"projectId":33368,"name":"Request","color":"#ff9200","displayOrder":2,"templateSummary":null,"templateDescription":null},
{"id":140153,"projectId":33368,"name":"Other","color":"#2779ca","displayOrder":3,"templateSummary":null,"templateDescription":null}
]
If we want to add a Task issue, we will use the id number 140151.
To get priority list:
Send GET request to URL example:
https://xx.backlog.com/api/v2/priorities?apiKey=abcdefghijklmn
This will return a list of id numbers that correspond to priorities: High, Normal, Low.
For example:
[
{
"id": 2,
"name": "High"
},
{
"id": 3,
"name": "Normal"
},
{
"id": 4,
"name": "Low"
}
]
Sending the request to add issue:
With the required information we’ve obtained earlier, we can build a JSON form body/file to add the issue. For example, the JSON will contain the parameters:
{
"projectId":33368,
"summary":"This is the title/subject of the issue",
"issueTypeId":140151,
"priorityId":3
}
This will add a task issue with normal priority.
Then we send a POST request to the URL endpoint for adding issues, for example:
https://xx.backlog.com/api/v2/issues?apiKey=abcdefghijklmn
This will return an HTTP 201 response code indicating that we have added the task to the specified project successfully. The response body will also contain more information about the issue.
If we want to add other info, e.g. the issue description or assignee, etc., we can use additional parameters in the JSON request.