2

I have found this answer in how to create an issue in jira via rest api?

POST to this URL

https://<JIRA_HOST>/rest/api/2/issue/

This data:

{
"fields": {
   "project":
   { 
      "key": "<PROJECT_KEY>"
   },
   "summary": "REST EXAMPLE",
   "description": "Creating an issue via REST API",
   "issuetype": {
      "name": "Bug"
   }
  }
}

In received answer will be ID and key of your ISSUE:

{"id":"83336","key":"PROJECT_KEY-4","self":"https://<JIRA_HOST>/rest/api/2/issue/83336"}

Don't forget about authorization. I used HTTP-Basic one.

Which I believe describes how to create an issue via posting to a url.

The problem is, I have no clue how this is actually implemented.

How does one POST to a url?

Is this the same as PHP post?

Where is the data kept?

What language is this all written in?

Sorry for such a vague question, This is all just so brand new to me I don't even know where to start researching this >_< Any sort of concrete example would be really really helpful!

Thank you!

Community
  • 1
  • 1
Indigo
  • 962
  • 1
  • 8
  • 23

1 Answers1

0

The data section is written in JSON format, which is simply a text representation of a data structure. It is indented for readability, but really could be shown as:

{"fields":{"project":{"key": ""},"summary": "REST EXAMPLE","description":"Creating an issue via REST API","issuetype":{"name": "Bug"}}}

To POST to a URL and create an issue, you need a server-side mechanism to first authenticate aginst Jira, then send the data using HTTP POST. In PHP, you can use cURL to POST or GET, or file_get_contents() to GET. PHP cURL doc is here: http://php.net/manual/en/book.curl.php

For example, here's a PHP function to create a Jira issue (after authentication):

public function createIssue(){
    /*
    Issue types:
        1:  Bug
        3:  Task
        5:  Sub-task
    */
    $out = false;
    $this->method = "POST";
    $this->url = "http://10.50.25.64:8080/rest/api/2/issue/";
    $this->data = array(
    "fields" => array(
        "project" => array("key" => $this->projectKey),
        "summary" => $this->summary,
        "environment" => $this->environment,
        "description" => $this->description,
        "issuetype" => array("id" => $this->issueType),
        )
    );
    if (!empty($this->assignee)) $this->data['fields']['assignee'] = $this->assignee;
    if (!empty($this->labels)) $this->data['fields']['labels'] = $this->labels;
    foreach($this->customFields as $key => $val){
        $this->data['fields'][$key] = $val;
    }
    $issue = $this->execCURL();
    return $issue;
}

The function execCURL() takes the PHP array ($this->data) and sends it using PHP cURL.

Hope any of this helps!

Webomatik
  • 844
  • 7
  • 7