I was trying to create a user in PHP. My code is shown below:
$urltopost = "http://mysite.freshdesk.com/contacts.xml";
$header[] = "Content-type: application/xml";
$datatopost = "<user><name>".$fname." ".$lname."</name><email>".$email."</email></user>";
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, FRESHDESK_USER_NAME . ":" . FRESHDESK_PASSWORD);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$returndata = curl_exec ($ch);
echo($returndata);
However the result that I get is the following:
You are being redirected.
The "redirected" is a link to:
https://mysite.freshdesk.com/contacts.xml
I started off writing this not knowing why I was getting the above error but then I realised.
I had set up security to always use SSL. I had specified
$urltopost = "http://mysite.freshdesk.com/contacts.xml";
where it should have been:
$urltopost = "https://mysite.freshdesk.com/contacts.xml";
When I did this the user was created and the XML was returned.
I hope that this helps somebody out there as it took me a while to work out what was going on.
David