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

How to add component while creating an issue via JIRA REST API

Roman Gulevskiy September 28, 2014

I can't understand what I'm missing

Without "component" filed it works just fine, but I can't create issue with defined component.

It gives me "components => string 'data was not an array'" error.

 

$new_issue = array(

 

    'fields' => array(

        'project' => array('id' => '10602'),

        'summary' => 'TEST',

        'issuetype' => array('id' => '3'),

        'reporter' => array('name' => 'myname'),

        'components' => array('id' => '10705'),

        )

);

1 answer

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
Matheus Fernandes
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 28, 2014

Hi Roman,

You'll actually need to pass the Components field as an array instead of simply adding it as an element to the new_issue array. Take a look in the example of the /rest/api/2/issue REST API:

{
    "update": {
        "worklog": [
            {
                "add": {
                    "started": "2011-07-05T11:05:00.000+0000",
                    "timeSpent": "60m"
                }
            }
        ]
    },
    "fields": {
        "project": {
            "id": "10000"
        },
        "summary": "something's wrong",
        "issuetype": {
            "id": "10000"
        },
        "assignee": {
            "name": "homer"
        },
        "reporter": {
            "name": "smithers"
        },
        "priority": {
            "id": "20000"
        },
        "labels": [
            "bugfix",
            "blitz_test"
        ],
        "timetracking": {
            "originalEstimate": "10",
            "remainingEstimate": "5"
        },
        "security": {
            "id": "10000"
        },
        "versions": [
            {
                "id": "10000"
            }
        ],
        "environment": "environment",
        "description": "description",
        "duedate": "2011-03-11",
        "fixVersions": [
            {
                "id": "10001"
            }
        ],
        "components": [
            {
                "id": "10000"
            }
        ],
        "customfield_60000": "jira-developers",
        "customfield_20000": "06/Jul/11 3:25 PM",
        "customfield_80000": {
            "value": "red"
        },
        "customfield_40000": "this is a text field",
        "customfield_30000": [
            "10000",
            "10002"
        ],
        "customfield_70000": [
            "jira-administrators",
            "jira-users"
        ],
        "customfield_50000": "this is a text area. big text.",
        "customfield_10000": "09/Jun/81"
    }
}

While Summary is:

"summary": "something's wrong",

The Components field is:

"components": [
            {
                "id": "10000"
            }
        ]

Does that make sense? smile

Roman Gulevskiy September 28, 2014

yes, thanx, I've seen this) but I don't know what I should change in my code, I'm not really good at php, 'components' => array('id' => '10705'), maybe you can help me a little bit with syntax, please?

Roman Gulevskiy September 28, 2014

oh, I did it, I had just put additional [] brackets to components, thanx again!

Matheus Fernandes
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 28, 2014

Hey Roman, I'm glad to hear that! :) You are most welcome!

TAGS
AUG Leaders

Atlassian Community Events