Good morning all,
I'm trying to create a lead entity in Microsoft Dynamics NAV 365, from a php CURL script. However I keep getting a "HTTP Error 401 - Unauthorised: Access is denied" in my CURL response. I can however, create a lead via the web interface fine.
I've created my object from the lead entity type as described on the MSDN docs website.
Below is my code:
$lead = array('person' =>
array(
'topic' => 'WEB LEAD',
'name' => $fullname,
'firstname' => $firstname,
'lastname' => $lastname,
'companyname' => $company,
'telephone1' => $telephone,
'emailaddress1' => $email,
'description' => $comment,
),
);
$dynamics = $url . '/api/data/v8.2/leads';
$ch = curl_init($dynamics);
$options = array(
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json; charset=utf-8',
'OData-MaxVersion: 4.0',
'OData-Version: 4.0',
'Accept: application/json',
),
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_USERPWD, 'username:password',
CURLOPT_POSTFIELDS => json_encode($lead),
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$responseInfo = curl_getinfo($ch);
curl_close($ch);