Android™ Jira - Issues: Create Issue

Back to Index

Creates an issue or a sub-task from a JSON representation.

Documentation: https://developers.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-post

CURL Command

curl -X POST --user jira@example.com:JIRA_API_TOKEN \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '
    {
      "fields": {
        "project": {
          "id": "10000"
        },
        "summary": "something is wrong",
        "issuetype": {
          "id": "10000"
        },
        "assignee": {
          "name": "matt"
        },
        "priority": {
          "id": "3"
        },
        "labels": [
          "bugfix",
          "blitz_test"
        ],
        "description": "description",
        "fixVersions": [
          {
            "id": "10001"
          }
        ],
        "customfield_10005": "blah blah"
      }
    }' \
  --url 'https://your-domain.atlassian.net/rest/api/2/issue'

Android™ Example

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    CkRest rest = new CkRest();
    boolean success;

    //  URL: https://your-domain.atlassian.net/rest/api/2/issue
    boolean bTls = true;
    int port = 443;
    boolean bAutoReconnect = true;
    success = rest.Connect("your-domain.atlassian.net",port,bTls,bAutoReconnect);
    if (success != true) {
        Log.i(TAG, "ConnectFailReason: " + String.valueOf(rest.get_ConnectFailReason()));
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    rest.SetAuthBasic("jira@example.com","JIRA_API_TOKEN");

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("fields.project.id","10000");
    json.UpdateString("fields.summary","something is wrong");
    json.UpdateString("fields.issuetype.id","10000");
    json.UpdateString("fields.assignee.name","matt");
    json.UpdateString("fields.priority.id","3");
    json.UpdateString("fields.labels[0]","bugfix");
    json.UpdateString("fields.labels[1]","blitz_test");
    json.UpdateString("fields.description","description");
    json.UpdateString("fields.fixVersions[0].id","10001");
    json.UpdateString("fields.customfield_10005","blah blah");

    rest.AddHeader("Content-Type","application/json");
    rest.AddHeader("Accept","application/json");

    CkStringBuilder sbRequestBody = new CkStringBuilder();
    json.EmitSb(sbRequestBody);
    CkStringBuilder sbResponseBody = new CkStringBuilder();
    success = rest.FullRequestSb("POST","/rest/api/2/issue",sbRequestBody,sbResponseBody);
    if (success != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
        Log.i(TAG, "Response Header:");
        Log.i(TAG, rest.responseHeader());
        Log.i(TAG, "Response Body:");
        Log.i(TAG, sbResponseBody.getAsString());
        return;
        }

    CkJsonObject jsonResponse = new CkJsonObject();
    jsonResponse.LoadSb(sbResponseBody);

    String id;
    String key;
    String self;

    id = jsonResponse.stringOf("id");
    key = jsonResponse.stringOf("key");
    self = jsonResponse.stringOf("self");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Sample JSON Response Body

{
  "id": "10023",
  "key": "SCRUM-24",
  "self": "https://chilkat.atlassian.net/rest/api/2/issue/10023"
}