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

Create Issue with Component (REST API + PHP)

João Corrêa December 11, 2015

This question is in reference to Atlassian Developer Documentation: JIRA REST API Example - Create Issue

Hello guys,

 

I'm trying to create an issue with php and rest api but I always get {"errorMessages":[],"errors":{"components":"data was not an array"}}.


My code is:

<?php
$username = 'myuser';
$password = 'mypass';             
$url = "https://myinstance.atlassian.net/rest/api/2/issue/";
$data = array(
    'fields' => array(
        'project' => array(
            'key' => 'KEY',
            ),
        'summary' => 'Test',
        'reporter' => array(
            "name" => "user.test"
            ),
        'description' => 'This is description',
        'components' => array(
                "name" => "JIRA"
                ),
        "issuetype" => array(
            "name" => "Service Request",
            "subtask" => false
            ),
        ),
    );
$ch = curl_init();
$headers = array(
    'Accept: application/json',
    'Content-Type: application/json'
    );
$test = "This is the content of the custom field.";
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
print_r(array_values($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
    echo "cURL Error: $ch_error";
} else {
    echo $result;
}
curl_close($ch);  
?>

 

I've tried to turn components optional on JIRA and remove this field from PHP and it works.
Can someone help me?

Thanks in advance!

João Corrêa 

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
João Corrêa December 16, 2015

I've successfully solved this issue with this piece of code:

 

"components" => array (0 => array(
            'name' => 'component_name',
            ),
0 votes
filiprogaczewski
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.
December 16, 2015

Hey João,

Can you paste the full JSON sent to JIRA for request which includes components? 


Cheers,

Filip

TAGS
AUG Leaders

Atlassian Community Events