API Creating a user in php

  • 4 July 2012
  • 6 replies
  • 139 views

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


This topic has been closed for comments

6 replies

Hi David,

Thanks for your feedback on this.

We will fix the error & return messages soon in Freshdesk.

regards
Vijay

Has this been fixed?

David, you saved me lot of time. Thanks alot.


+1 David, saved me a bunch of time too.


@freshdesk just give me an error that tells me I need to use SSL. This has been a bug for 3 years!


Userlevel 4
Badge +12

Hi,




We've improved error coding in our API V2 response. For more details, please visit the site : developer.freshdesk.com/api




Cheers!


I wish to send a screen shot to "Firefox and CCK2"forum, RegT

 


screenshot11-19-17at03.23pm_29958.png