Learner
Learner

Reputation: 1315

JIRA API create issue with custom fields

i want to create an issue in JIRA by using the REST API provided by JIRA. i am able to create a simple issue,

using this :

   http://localhost:8080/rest/api/latest/issue

and data as follows:

   {"fields":{"project":{"key": "TES"},"summary":"user name not showing validation message","description":"Hi validation is missing from user name","issuetype": {"name": "Bug"},"reporter":{"name":"BruceWayne"}  }}

this is running fine.

now i want to add 3 custom fields while creating an issue. The custom fields are Authorname, AuthorTag,AuthorID. how can i do this in rest api. what should i add in my data.

My sample data is as follows:-

   {"fields":{"project":{"key": "TES"},"summary":"my bugs 5","description":"Hi","issuetype": {"name": "Bug"},
       "customfield_10000":"[email protected]",
       "customfield_10100":{"value":"abc"},
       "reporter":{"name":"amit"},
       "components": [{
                 "add" : {"name" : "abc"}
                }],"priority": {
 "id": "1"
  }

      }}

i want to use the names specified for customfields rather than customfield_XXXXX .

One way i think of is to hit the API after creating a simple issue ( using another API hit to get meta data as follows)

 http://localhost:8080/rest/api/latest/issue/tes-79?expand=editmeta

and then do json parsing and again issue a put command to update the fields in same issue

but i was looking for a way to do it in single API hit (while creating an issue)

Upvotes: 0

Views: 3387

Answers (2)

N00b Pr0grammer
N00b Pr0grammer

Reputation: 4647

I know that it is very late to answer this question, but then might help others if not the OP at this time of writing.

If you're in doubt about the create, then you could do something like this - Try a GET on an issue that you would rather create manually with the new parameters as well and then based on the output of the same you could then decide to update it with the new parameters with the new name or the old-fashioned customfield_xxx field.

Try a GET like this on cURL

curl -D- -u fred:fred -X GET -H "Content-Type: application/json" https://jira.fred.com/rest/api/2/issue/FRD-88651

Then you could possibly do a POST like how you've done earlier:

http://localhost:8080/rest/api/latest/issue

Upvotes: 0

mdoar
mdoar

Reputation: 6881

It should be just like setting any other field, but you have to use the field name "customfield_NNNNN" instead

Upvotes: 1

Related Questions