Create Jira issue via rest api - python

shani hayoun September 9, 2013

Hi,

We're using Jira v5.1.2 and we try to create new Jira issue via rest api.

we run :

cmd = "curl.exe -D- -u user:pass -X POST --data @data_to_send.json -H 'Content-Type: application/json' 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0' http://outJiraSite/rest/api/2/issue/"

subprocess.check_call(cmd)

 

data_to_send.json:

{
           "fields" : {
               "project": {
                   "key": "CT"
               },
               "summary": "testing",
               "assignee": {
                   "name": 'team'
               },
               "issuetype": {
                   "name": "Task"
               },
               "description": "Testing automatic create Jira Issue  \n",           
               }
         }

and get :

curl: (6) Could not resolve host: (nil); Host not found
HTTP/1.1 415 Unsupported Media Type
Date: Tue, 10 Sep 2013 07:38:46 GMT
Server: Apache-Coyote/1.1
X-AREQUESTID: 38x583x1
X-Seraph-LoginReason: OK
X-ASESSIONID: 6n27hs
X-AUSERNAME: --------
Content-Type: text/html;charset=utf-8
Content-Length: 1117
Set-Cookie: JSESSIONID=----------------------------------; Path=/; HttpOnly
Set-Cookie: atlassian.xsrf.token=BBOO-X31J-0L8A-OSLQ|---------------------|lin; Path=/

<html><head><title>Apache Tomcat/6.0.32 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 415 - Unsupported Media Type</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Unsupported Media Type</u></p><p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the requested resource for the requested method (Unsupported Media Type).</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.32</h3></body></html>

Can you please help and advice?


Is there any other way to create Jira issue via rest api?

Thanks!!

Shani

7 answers

1 accepted

0 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 11, 2013

to add watchers then try with this rest api

https://docs.atlassian.com/jira/REST/latest/#idp1964032

shani hayoun September 11, 2013

Thank you! it work!!

1 vote
Pedro Cora
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 9, 2013

I'm not sure what is wrong on your json file, but try the following:

{
    "fields": {
       "project":
       { 
          "key": "AWD"
       },
       "summary": "Issue created via REST.",
       "description": "bla bla bla goes here",
       "issuetype": {
          "name": "Task"
       }
   }
}

And also reduce your call to: curl -D- -u user:pass -X POST --data @data.json -H 'Content-Type: application/json' http://localhost:8080/rest/api/2/issue/

0 votes
shani hayoun September 14, 2013

Please help Please help!!

I'm try to serch Jira issue , my URL is "http://MyJira.com/rest/api/2/search?jql=summary~'DOA_DigitalZoom_Smooth failed on C16'"

I run this using json.loads but it can't find this issue although this issue existing!!!!

Can you please help? what wrong in my url?

Thanks you!

Fabian Bolte October 30, 2013

I solved a similar problem by URL-encoding the query string.

(Try posting additional problems as new question. There's no incentive to look into questions that are already marked as answered.)

0 votes
shani hayoun September 11, 2013

Hi,

I've one more question please, is there any way to add watchers to ticket via rest api?

I can’t find it here - https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Create+Issue

Thank you!

Shani

0 votes
shani hayoun September 10, 2013

Hi,

Thank you all. I had several mistakes in my fields request…

Finally, I didn’t use Curl and I used urllib2.Request…and it work!

I’ve one more question please; I like to search jira ticket by summary.

My url is : http://host.com/rest/api/2/search?jql=summary~[x][y][Unstable]- TestGroup/Test failed on 16.

Since my url contain spaces, it can’t find issue.

Do you know how can I overpower this problem?

Thank you very much!

Shani

GOUTHAM KUMAR YELLRAPU December 8, 2020

Hi @shani hayoun 

 

creating jira issues   using RESTAIP python .can you help me. 

0 votes
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 9, 2013

generally what is the URL using to login to jira i mean something like

Jira.atlassian.com:8080 or Jira.atlassian.com:8080/jira?

0 votes
Mirek
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2013

Hi,

Take a look at Python Client for JIRA

https://marketplace.atlassian.com/plugins/com.atlassian.jira.jira-python-rest

With this client you will be able to very easily connect and create JIRA issues.

Full documentation:

http://jira-python.readthedocs.org/en/latest/

I hope that will help.

Best Regards,

Mirek

Suggest an answer

Log in or Sign up to answer