2014-05-14 4 views
0

아래 코드를 실행하려고하면 이름이 너무 짧습니다 (최소 1 자). RestSharp v104.1을 사용하고 있습니다. 새로운 사용자를 만들려고 할 때 읽으려고해도 문제가 없습니다.RestSharp를 사용하는 ZenDesk의 오류 : 이름이 너무 짧습니다.

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\":\"[email protected]\" }}"; 

     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(); 
    } 

답변

관련 문제