I have built a form in PHP that submits via AJAX to a script that needs to post to the Workfront API to create a new task in a generic catch-all project.
When I put the following URL + Query in the browser (Chrome) address bar it did successfully create the the task, so now I need to adapt it to work in PHP:
https://MY-DEPT-NAME.preview.workfront.com/attask/api/v9.0/task/?name=New%20Task&description=This%20is%20my%20wonderful%20shiney%20new%20task&method=POST&apiKey=8ffskq9hj3q0swnzi6z1ixf9tl8qbop8&projectID=5b6358d7002b1b5c69342a098d752158
Here is the code I have, based partially on Workfront sample code in GitHub. Can you see what I am missing or doing wrong? (The name and description will be replaced with input from the form.)
$url = "https://MY-DEPT-NAME.preview.workfront.com/attask/api/v9.0/task/";
$data = array(
'name' => 'My New Task',
'description' => 'This is my wonderful shiney new task',
'method' => 'POST',
'apiKey' => '8ffskq9hj3q0swnzi6z1ixf9tl8qbop8',
'projectID' => '5b6358d7002b1b5c69342a098d752158'
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
if ($data){
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
var_dump( $result );
curl_close( $curl );
var_dump( $curl );
The result I am currently getting from those var_dump's is: "bool(false) resource(1) of type (Unknown)"