For one of our contractors we have to upload json files to their zoho account.
We have tried different ways to do this, directly with reading the file contents or in trying to directly insert Json string.
But none of these worked.
We always received the respone message : EMPTY_OR_NO_FILE_SPECIFIED
Could someone help on this ?
Here is one of the latest tried code :
public static void PostAsync(int sourceApiId)
{
string url = "https://apidocs.zoho.com/files/v1/upload?filename=Stock_snapshot20210210.json&fid=lz6x5c7bb900ad31343eeb9fe1a76c63d2a52&scope=docsapi";
byte[] data = Encoding.UTF8.GetBytes(jsonString);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.Headers.Add("Authorization", "Zoho-oauthtoken " + token);
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string responseContent = reader.ReadToEnd();
JObject adResponse = JsonConvert.DeserializeObject<JObject>(responseContent);
Console.WriteLine(adResponse);
Console.WriteLine(request.Address);
Console.WriteLine(request.Headers);
}
}
catch (WebException webException)
{
if (webException.Response != null)
{
using (StreamReader reader = new StreamReader(webException.Response.GetResponseStream()))
{
string responseContent = reader.ReadToEnd();
Console.WriteLine(JsonConvert.DeserializeObject<JObject>(responseContent));
}
}
}
Console.ReadLine();
}