Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to use REST API to create Issue in gadget?

Arthur
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 Leaders.
September 1, 2013

Hi folks,

in my jira gadget I have several AJS.$.ajax() GET calls to get all meta information to create an Issue and finally an ajax POST("baseurl/rest/api/2/issue") call to create an Issue.

When I run my gadget at localhost with "atlas-run" everything works fine, but when I package it and deploy it on our production JIRA, I get an error response "400 Bad Request" with the JSON Response:

{"errorMessages":[],"errors":{"priority":"Field 'priority' cannot be set. It is not on the appropriate screen, or unknown.","labels":"Field 'labels' cannot be set. It is not on the appropriate screen, or unknown.","customfield_10072":"Field 'customfield_10072' cannot be set. It is not on the appropriate screen, or unknown."}}

I also checked my permissions, they are all fine. Running jira 5.2.11 - 6.0.7

I searched in several forums and found another dev who had the same problem, and he solved it by providing a BASIC Authentication with username and password in the POST call.

Two things about that:

  1. In the Atlassian REST API Documentation, under Authentication you can find this line: "The log-in page uses cookie-based authentication, so if you are using JIRA in a browser you can call REST from Javascript on the page and rely on the authentication that the browser has established. [...]"
  2. One cannot get the password of the current logged in user, so basic authentication doesnt work here anyways

Am I totally on the wrong way?

Any idea?

thanks in advance

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
RambanamP
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 Leaders.
September 1, 2013

can you confirm all the fields i.e "Priority", "labels" and "customfield_10072" are in edit screen and you have edit permission on that issue?

Arthur
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 Leaders.
September 1, 2013

Aarrrghhh!! That was it!!(edit screen) what a shame... blackout!

Thank you so much! I had struggled 2 whole days with that..

RambanamP
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 Leaders.
September 1, 2013

Glad to hear it worked!!!

Cheers!!!

0 votes
Arthur
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 Leaders.
January 9, 2014

Yo Smruti,

I just used jquery ajax for the rest calls.

something like:

jquery.ajax({
type: "POST",
url: "your-jira-host/rest/api/2/issue",
data: /* see create issue rest api reference for request data */
})
.done(function( responsedata) {
alert( "Data Retrieved: " + responsedata);
});

before that POST call you need another rest GET call to get the metadata for creating issues

0 votes
S January 8, 2014

Hi Arthur,

I'm trying to create issues by making rest calls in a gadget. I'm returning html cpntent from my resource to display the gadget. To build html content I'm using vm files.

Can you please give me an example of how you made the rest call from your gadget.

Thanks,

Smruti

0 votes
Arthur
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 Leaders.
September 1, 2013

solved... I was dumb and blind, I forgot to get a list of available fields for creating issue, I thought a list of ALL FIELDS would do it. It's in the issue/createmeta under issuetypes....

(copied from doc)

"issuetypes": [
                {
                    "self": "http://www.example.com/jira/rest/api/2/issueType/1",
                    "id": "1",
                    "description": "An error in the code",
                    "iconUrl": "http://www.example.com/jira/images/icons/issuetypes/bug.png",
                    "name": "Bug",
                    "subtask": false,
                    "fields": {
                        "issuetype": {
                            "required": true,
                            "name": "Issue Type",
                            "operations": [
                                "set"
                            ]
                        }
                    }
                }
            ]

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events