APIs & Integrations

rameshbabu745
Membro

Getting error: The remote server returned an error: (400) Bad Request. using oAUTH

I am using test account to create a integration at the time i am getting error like "The remote server returned an error: (400) Bad Request."

 

I am using Asp.Net C# below is my code,

 

WebRequest request = WebRequest.Create("https://api.hubapi.com/oauth/v1/token/");
request.Method = "POST";

var postData = "grant_type=authorization_code";
postData += "&client_id=" + ConfigurationManager.AppSettings["hubspot.clientid"].ToString();
postData += "&client_secret=" + ConfigurationManager.AppSettings["hubspot.clientsecret"].ToString();
postData += "&redirect_uri=" + ConfigurationManager.AppSettings["hubspot.redirecturi"].ToString();
postData += "&code=" + code;

byte[] byteArray = Encoding.UTF8.GetBytes(postData);

request.ContentType = "application/x-www-form-urlencoded;charset=utf-8";

request.ContentLength = byteArray.Length;

Stream dataStream = request.GetRequestStream();

dataStream.Write(byteArray, 0, byteArray.Length);

dataStream.Close();

WebResponse response = request.GetResponse();

Console.WriteLine(((HttpWebResponse)response).StatusDescription);

dataStream = response.GetResponseStream();

StreamReader reader = new StreamReader(dataStream);

string responseFromServer = reader.ReadToEnd();

Console.WriteLine(responseFromServer);

reader.Close();
dataStream.Close();
response.Close();

 

P.S - https://developers.hubspot.com/changelog/upcoming-changes-to-the-public-api-demo-account

Above article says "POST" didnt work. That things have issue for this ?

0 Avaliação positiva
2 Respostas 2
himanshurauthan
Autoridade no assunto | Parceiro Elite
Autoridade no assunto | Parceiro Elite

Getting error: The remote server returned an error: (400) Bad Request. using oAUTH

Hello @rameshbabu745

Can you please confirm if you are sending the CODE value correctly obtained from an iniated oauth connection?

Thanks
Digital Marketing & Inbound Expert In Growth Hacking Technology
0 Avaliação positiva
rameshbabu745
Membro

Getting error: The remote server returned an error: (400) Bad Request. using oAUTH

using this line postData += "&code=" + code;

I am getting proper code value then only sending

0 Avaliação positiva