How to add issues using Backlog API

As a primer for sending Backlog API requests, please see Basic intro to sending Backlog API requests.


Adding an issue via Backlog API

According to the Backlog API documentation, 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.

To get the required info, we can use CURL to send requests to Backlog API.

Get project id:

Get project id path: /api/v2/projects/[project key]

Example:

curl https://xx.backlog.com/api/v2/projects/COMDEMO?apiKey=abcdefghijklmn

The JSON response will 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 is 33368. We will need it later to send the request to add issues to this project.

Get list of issue types from the project:

Get issue types path: /api/v2/projects/[project id or key]/issueTypes

Example:

curl 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.

Get priority list:

Get priority list path: /api/v2/priorities

Example:

curl 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"
  }
]

:star: Sending the CURL POST request to Backlog API to add an 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 code will contain the minimum required parameters:

{
    "projectId":33368,
    "summary":"This is the title/subject of the issue",
    "issueTypeId":140151,
    "priorityId":3
}

The Add issues path is /api/v2/issues

So, the curl POST command will be:

curl -X POST https://spaceid.backlog.com/api/v2/issues?apiKey=abcdefghijklmn -H 'Content-Type: application/json' 
-d '{
    "projectId":33368,
    "summary":"This is the title/subject of the issue",
    "issueTypeId":140151,
    "priorityId":3
   }'

When successful, this will return an HTTP 201 response code indicating that we have added the task to the specified project. The response body will also contain more information about the issue.

Example using reqbin to send a CURL POST JSON request:

If we want to add other info, e.g. the issue description or assignee, etc., we can add additional parameters in the JSON code when we send the request to Backlog API.

:warning: Important edit: Adding issues with custom fields

I realized that I’d made an error about adding issues above, my apologies. The form parameters as documented in the Backlog API is

Content-Type:application/x-www-form-urlencoded

This means the data to be sent should not be in JSON format. But in the format:

curl -X POST https://[spaceid].backlog.com/api/v2/issues?apiKey=[yourAPIkey]
-H “Content-Type: application/x-www-form-urlencoded”
-d “param1=value1&param2=value2”

This is important if you are adding issues with custom fields to be filled.

How can I add custom fields while creating issue using add issue API?

I am using as below but it does not work. The following command create issue but does not populate the custom fields.

curl -X POST https://spaceid.backlog.com/api/v2/issues?apiKey=abcdefghijklmn -H 'Content-Type: application/json' 
-d '{
    "projectId":33368,
    "summary":"This is the title/subject of the issue",
    "issueTypeId":140151,
    "priorityId":3,
    "customField_6680": 1234
   }'

Note: here 6680 is the id of created custom field.

Ref: Add Issue | Backlog Developer API | Nulab

Hi @rvpandya93

I checked with our Backlog Tech Support team, the issue is you’re trying to post parameters in JSON.

But as written in the API reference, parameters should be posted in the context of form parameters.

I think perhaps can you try similar to this format?
from https://reqbin.com/req/c-sma2qrvp/curl-post-form-example

curl -X POST https://[spaceid].backlog.com/api/v2/issues?apiKey=[yourAPIkey]
   -H "Content-Type: application/x-www-form-urlencoded" 
   -d "param1=value1&param2=value2" 

Thus, adding issue with custom field:

curl -X POST https://[spaceid].backlog.com/api/v2/issues?apiKey=[yourAPIkey]
   -H 'Content-Type:application/x-www-form-urlencoded'
   -d 'projectId=58693&summary=”This is the title/subject of the issue"&issueTypeId=248839&priorityId=3&customField_6680=[yourvalue]'

Another syntax:

curl https://[spaceid].backlog.com/api/v2/issues?apiKey=[yourAPIkey]
   -d 'projectId=58693&summary=”This is the title/subject of the issue"&issueTypeId=248839&priorityId=3&customField_6680=[yourvalue]'

My earlier example of using JSON for adding issue works only for adding issues without custom fields, but the correct format should be using form parameters. So I’ve corrected it above.

I’m having trouble with only html being returned even though my content type header is specified as Content-Type: application/json;charset=utf-8

I’m just using GET requests at the first part of the tutorial, but unable to get a json response. Any ideas?

Hi @jordan_webb

I think if you’re using GET requests, you can omit the content type header when sending your GET request.

Example, typing this in the terminal to get the project id:

curl https://[yourspaceid].backlog.com/api/v2/projects/[projectKey]?apiKey=abcdefghijklmn

The response body will be in JSON format.

Can you give that a try?

If it doesn’t work, can you let me know which part of the tutorial are you at?


Add-on:

For POST requests, you can specify the content type header to inform the server about the data you’re sending.

E.g. if you’re sending JSON, you’ll specify in the content type header that it’s JSON.

From Mozilla web docs:

In requests, (such as POST or PUT), the client tells the server what type of data is actually sent.

@soohian00 Thank you very much. This worked and I was able to complete the tutorial and programmatically add an issue to my project. Great support!

1 Like

@jordan_webb You’re welcome, glad to have helped! :slight_smile:

1 Like