Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need to specify Sprint Information in Rest API request.

Priyanka Mathur
January 31, 2018

HI Team,

 I am trying to create a Jira issue using Rest API and need to specify which sprint this issue needs to be created. 

I have used below schema, however, the "bad request " error is thrown.

1.

      "fields": {

        "project": {

          "id": "10000"

        },

        "summary": "something'\''s wrong",

        "issuetype": {

          "id": "10000"

        },

        "assignee": {

          "name": "homer"

        },

        "reporter": {

          "name": "smithers"

        },

        "priority": {

          "id": "20000"

        },

“Sprint: : {

“name”: “Sprint1:

},

        "labels": [

          "bugfix",

          "blitz_test"

        ]

Throws bad request error

      "fields": {

        "project": {

          "id": "10000"

        },

        "summary": "something'\''s wrong",

        "issuetype": {

          "id": "10000"

        },

        "assignee": {

          "name": "homer"

        },

        "reporter": {

          "name": "smithers"

        },

        "priority": {

          "id": "20000"

        },

“Sprint: :  “Sprint1",

        "labels": [

          "bugfix",

          "blitz_test"

 

 

this as well throws "bad request" error.

 

 

        ],

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
January 31, 2018

There must be a error message together with the bad request error. What is the error?

Priyanka Mathur
January 31, 2018

Nothing, It just states Reason Phase as blank and status as "bad request"

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
January 31, 2018
Priyanka Mathur
February 1, 2018

I was trying to use this example 

https://confluence.atlassian.com/jirakb/creating-an-issue-in-a-sprint-using-the-jira-rest-api-875321726.html

However i am creating a class to send the data 

public class Fields
{
public Project project { get; set; }
public string summary { get; set; }
public string description { get; set; }
public int customfield_XXXXX { get; set; }

}

 

this is giving bad request as well.

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
February 1, 2018

That is right because if you generate a json from the class it will not be the json you need. Jira accepts only certaion jsons. In your case it must be like this

{
    "fields": {
       "project":
       {
          "key": "SP"
       },
       "summary": "Sprint issue test",
       "description": "REST APIs are great.",
       "issuetype": {
          "name": "Bug"
       },
       "customfield_10001": 1
 }
}

Your Json will be like this

 {"project":"SP",
 "summary": "Sprint issue test",
 "description": "REST APIs are great.",
" customfield_XXXXX": "Sprint 1"}

It is a bad request. You need to create a class with the fields variable which is of the  Fields class. Also you need to create a project class with the key variable and the project variable in Fields class must be of this class. And you also need an issue type.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events