Skip to main content

I use the following code for create user.


static void Main(string[] args)
{

string json = "{\"user\": {\"email\":\"test@test.com\",\"name\":\"Super man\"}}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://domain.freshdesk.com/contacts.json");
//HttpWebRequest class is used to Make a request to a Uniform Resource Identifier (URI).
request.ContentType = "application/json";
// Set the ContentType property of the WebRequest.
request.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(json);
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
string authInfo = "Api_Key:qswMtWmKtdsdfldfjdl;
authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
request.Headers["Authorization"] = "Basic " + authInfo;
//Get the stream that holds request data by calling the GetRequestStream method.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
//Send the request to the server by calling GetResponse.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string Response = reader.ReadToEnd();
//return the response
Console.Out.WriteLine(Response);
}


In response I get {"require_login":true}.


How can I solve this Issue

vijayakumar,


{"require_login":true} will be thrown only if the credentials are wrong or improperly base 64 encoded. In this case, the API keywas given in the wrong place. 'Api_key' present in authIfo varibale is a placeholder to put you api key (i.e., before the colon)


Below  line 

string authInfo = "Api_Key:qswMtWmKtdsdfldfjdl;

 

Should be changed to

 

string authInfo = "qswMtWmKtdsdfldfjdl:X;

 

After the above changes are made, the program should properly run.


Let us know if you run into any issues.





Hi


I am using the below code and I still get the {"require_login":true} error. 




 URL oracle =new URL ("http://Flipkart.freshservice.com/helpdesk/tickets/filter/all_tickets?format=json");


 URLConnection uc = oracle.openConnection();

 String userpass = "Pwjlzk43j0CvmkZ6OUWp:X";

 String basicAuth = "Basic " + userpass ;

 uc.setRequestProperty ("Authorization", basicAuth);


 BufferedReader in = new BufferedReader(

 new InputStreamReader(oracle.openStream()));


 String inputLine;

 while ((inputLine = in.readLine()) != null)

 System.out.println(inputLine);

 in.close();

 }