I am trying to post some data to a website called Jira and create a new issue there with the data I send. I did try it with postman and it works! But now I just need to implement this in code. So far, this is what I managed to do and I know it is wrong but would like to know where and how to resolve it.
$args = array(
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Basic '.$apiKey
)
);
$bdy = array(
'key' =>'LD' ,
'summary'=> 'CODING WORKS',
"description" => "Creating of an issue using project keys and issue type names using the REST API",
"name"=> "Candidate"
);
$pload = array(
'method' => 'POST',
'timeout' => 30,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => $args,
'body' => json_encode($bdy)
);
$response = wp_remote_post ('',$pload);
In the variable $bdy
it should be like this in json format:
{
"fields": {
"project":
{
"key": "LD"
},
"summary": "CODING WORKS",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Candidate"
}
}
}
For instance the path from 'key' => 'LD'
should really be something like this project=>key=>'LD'
, but I don't know how to path it in WP/PHP.
I am trying to post some data to a website called Jira and create a new issue there with the data I send. I did try it with postman and it works! But now I just need to implement this in code. So far, this is what I managed to do and I know it is wrong but would like to know where and how to resolve it.
$args = array(
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Basic '.$apiKey
)
);
$bdy = array(
'key' =>'LD' ,
'summary'=> 'CODING WORKS',
"description" => "Creating of an issue using project keys and issue type names using the REST API",
"name"=> "Candidate"
);
$pload = array(
'method' => 'POST',
'timeout' => 30,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => $args,
'body' => json_encode($bdy)
);
$response = wp_remote_post ('https://mysite.atlassian/rest/api/2/issue',$pload);
In the variable $bdy
it should be like this in json format:
{
"fields": {
"project":
{
"key": "LD"
},
"summary": "CODING WORKS",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Candidate"
}
}
}
For instance the path from 'key' => 'LD'
should really be something like this project=>key=>'LD'
, but I don't know how to path it in WP/PHP.
1 Answer
Reset to default 0You have to build the array as the json array needs to be
$args = array(
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Basic '.$apiKey
)
);
$bdy = array(
'fields'=> array(
'project' => array(
'key' =>'LD'
),
'summary'=> 'CODING WORKS',
'description' => 'Creating of an issue using project keys and issue type names using the REST API',
'issuetype' => array(
'name'=> 'Candidate'
)
)
);
$pload = array(
'method' => 'POST',
'timeout' => 30,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => $args,
'body' => json_encode($bdy)
);
$response = wp_remote_post ('https://mysite.atlassian/rest/api/2/issue',$pload);