I'm trying to use this API and POST to it with the required parameters.
Using this code:
function postToService_php( $urlAbs, $data ) {
$dataJSON = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlAbs);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJSON);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($dataJSON))
);
$resultJSON = curl_exec($ch);
return $resultJSON;
}
$postData = array(
'UserName' => '*username*',
'Password' => '*password*',
'Area' => 1
);
var_dump(postToService_php('http://e20prodwebapi.esmartapi.com/api/Authenticate', $postData));
This seems to give string(0) "" as a result, what am I doing wrong here?