When I try to run the code below I have the error code: Name is too short (minimum is 1 characters). I'm using RestSharp v104.1. I don't have any problem if I try to read, just when I'm trying to create a new user.
static string requestUri = "https://subdomain.zendesk.com/api/v2";
static string username = "myusername";
static string password = "mypassword";
static void Main(string[] args)
{
string new_users = "{\"user\":{ \"id\":4000000001, \"name\":\"Robin 001\", \"email\":\"robin.001@company.com\" }}";
Console.WriteLine(WriteJSON(username, password, "/users.json", new_users));
Console.ReadLine();
}
public static string WriteJSON(string username, string password, string json, string to_write)
{
var client = new RestClient(requestUri);
client.Authenticator = new HttpBasicAuthenticator(username, password);
client.AddDefaultHeader("Content-type", "application/json");
client.UserAgent = "MozillaXYZ/1.0";
client.FollowRedirects = true;
client.MaxRedirects = 10;
var request = new RestRequest(json);
request.Method = Method.POST;
request.RequestFormat = DataFormat.Json;
request.AddBody(to_write);
IRestResponse response = client.Execute(request);
var content = response.Content;
System.Xml.Linq.XNode node = JsonConvert.DeserializeXNode(content, "root");
return node.ToString();
}
I have posted the same question in another place and here is the answer that helped me: https://github.com/restsharp/RestSharp/issues/535#issuecomment-43373031