2014-10-09 24 views
1

有沒有人使用Desk的公共API成功搜索客戶或公司?我正在使用RestSharp庫提交請求,這對於創建新公司或通過ID提取個別案例工作良好。這是我想要做的一個樣本。如何使用Desk API v2執行搜索

RestClient client = new RestClient(); 

client.Authenticator = RestSharp.Authenticators.OAuth1Authenticator.ForProtectedResource(Configuration.ApiKey, Configuration.SiteKey, Configuration.Token, Configuration.TokenSecret); 
client.BaseUrl = "https://imathlete.desk.com/api/v2"; 

string json = new JavaScriptSerializer().Serialize(new Dictionary<string, object> { 
    { "q", "my company" } 
}); 

RestRequest request = new RestRequest { 
    Method = Method.GET 
    , Resource = "companies/search" 
    , RequestFormat = DataFormat.Json 
}; 

request.AddBody(json); 

RestResponse response = (RestResponse)client.Execute(request); 
string data = System.Text.Encoding.ASCII.GetString(response.RawBytes); 

我已經嘗試切換出請求主體的「Q」爲任一「名」或「域」,但響應總是相同的:

{"message":"Invalid search parameters"} 

任何意見將是不勝感激。

回答

0

也許改變

Resource = "companies/search" 

Resource = "companies/search?" 

此外,一定要URI編碼的查詢字符串

調試技巧:

  • 使用PostMan chrome extension,其他瀏覽器可能有 類似工具
  • 檢查Desk應用程序中Desk 搜索框發送的網絡XHR請求。
相關問題