How do i post data to url with fields?

Question

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.net/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.

0
Thinsanta 4 months 0 Answers 11 views 0

Leave an answer