Bad Request 400

Bad Request 400

Hello Zoho,

When I am posting the request to your server from the API (Records APIs -- > Single Records APIs -- > Insert specific record)

to insert the Leads I am getting Bad Request error. I don’t understand why this happened. Previously I am posting the request for the Access Token and its response is correct but when I called the APIs to insert the Leads using generated Access Token I am getting the Bad Request Error.

Here is my code in c# to post the request.

 

  1. To Get Access Token

 

// https://accounts.zoho.com/oauth/v2/token?refresh_token={refresh_token}&client_id={client_id}&client_secret={client_secret}&grant_type=refresh_token

var AuthenticationUrl = Access_Token_Url + Refresh_Token + "&client_id=" + Client_Id + "&client_secret=" + Client_Secret + "&grant_type=" + Grant_Type;

ServicePointManager.Expect100Continue = false;

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(AuthenticationUrl);

request.Method = "POST";

request.ContentType = "application/json";

WebResponse response = request.GetResponse();

using (var sr = new StreamReader(response.GetResponseStream()))

{

    json = sr.ReadToEnd();

}

var serializer = new JavaScriptSerializer();

var AccessToken = serializer.Deserialize<ZohoCRMLeadsFields>(json);

access_Token = AccessToken.Access_token.ToString();

 

This code is working perfectly to get Access Token.

 

  1. To Insert specific Leads

 

private static bool SaveLeads(string access_Token, ZohoCRMLeadsFields zohoCRMLeadsFields)

{

    try

    {

        HttpClient httpClient = new HttpClient();

        httpClient.Timeout = TimeSpan.FromMilliseconds(600000);

        httpClient.DefaultRequestHeaders.Accept.Clear();

        httpClient.BaseAddress = new Uri(ZohoAPI_Base_URL);

        var HeadWithAuthenticationKey = "Zoho-oauthtoken  " + Access_Token.Trim();

        httpClient.DefaultRequestHeaders.Add(HttpRequestHeader.Authorization.ToString(), HeadWithAuthenticationKey);

        httpClient.DefaultRequestHeaders.Add(HttpRequestHeader.ContentType.ToString(), "application/json");

        using (httpClient)

        {

            try

            {

                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

                HttpResponseMessage response = httpClient.PostAsJsonAsync(Leads_URI, zohoCRMLeadsFields).Result;

                return response.IsSuccessStatusCode;               

            }

            catch (Exception ex)

            {

                return false;

            }

        }

    }

    catch (Exception ex)

    {

        return false;

    }

}

 

This is code where I am getting the Bad Request Error.

 

Please help to solved the problem.