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
Community moderators have prevented the ability to post new answers.
I've successfully solved this issue with this piece of code:
"components" => array (0 => array( 'name' => 'component_name', ),
Hey João,
Can you paste the full JSON sent to JIRA for request which includes components?
Cheers,
Filip
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.