I get the error in the picture when I get the data transmission code working in its my local environment to the server. By the way, my code is as follows;
public static class CrmIntegration
{
static string serviceUrl = "";
static HttpClient client = new HttpClient();
public static void InsertRecords(SendEmailCommand contactData)
{
Task<string> getToken = GetToken();
if (getToken != null)
{
string jsonToken = getToken.Result;
Token token = JsonConvert.DeserializeObject<Token>(jsonToken);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.zohoapis.com/crm/v2/Leads");
request.Method = "POST";
request.Headers["Authorization"] = $"Zoho-oauthtoken {token.access_token}";
JObject requestBody = new JObject();
JArray recordArray = new JArray();
JObject recordObject = new JObject();
recordObject.Add("First_Name", contactData.FirstName);
recordObject.Add("Mobile", contactData.PhoneNumber);
recordObject.Add("Email", contactData.Email);
recordObject.Add("Kategori", contactData.MessageType);
recordObject.Add("Last_Name", contactData.LastName);
recordObject.Add("Company", contactData.CompanyName);
recordArray.Add(recordObject);
requestBody.Add("data", recordArray);
string dataString = requestBody.ToString();
var data = Encoding.UTF8.GetBytes(dataString);
int dataLength = data.Length;
request.ContentLength = dataLength;
using (var writer = request.GetRequestStream())
{
writer.Write(data, 0, dataLength);
}
request.KeepAlive = true;
HttpWebResponse response;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
if (e.Response == null) { throw; }
response = (HttpWebResponse)e.Response;
}
HttpWebResponse responseEntity = response;
responseEntity.Close();
}
}
public static async Task<string> GetToken()
{
serviceUrl = "https://accounts.zoho.com/oauth/v2/token";
List<KeyValuePair<string, string>> pairs = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("refresh_token", "1000.{refresh_token}"),
new KeyValuePair<string, string>("client_id", "1000.{client_Id}"),
new KeyValuePair<string, string>("client_secret", "{client_secret}"),
new KeyValuePair<string, string>("grant_type", "refresh_token")
};
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;
try
{
HttpContent content = new FormUrlEncodedContent(pairs);
using (HttpResponseMessage response = await client.PostAsync(serviceUrl, content))
{
return await response.Content.ReadAsStringAsync();
}
}
catch (Exception ex)
{
throw;
}
}
}
class Token
{
public string access_token { get; set; }
public string token_type { get; set; }
public string expires_in { get; set; }
}