如何使用Desk API v2
本文关键字:v2 API Desk 何使用 | 更新日期: 2023-09-27 18:26:12
是否有人成功使用Desk的公共API搜索客户或公司?我正在使用RestSharp库提交请求,这对于创建新公司或按ID提取个别案例很有效。以下是我尝试做的示例。
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"换成"name"或"domain",但响应总是一样的:
{"message":"Invalid search parameters"}
如有任何建议,我们将不胜感激。
也许可以更改
Resource = "companies/search"
至
Resource = "companies/search?"
还要确保对查询字符串进行URI编码
调试提示:
- 使用PostMan chrome扩展,其他浏览器可能有类似的工具
- 检查桌面发送的网络XHR请求桌面应用程序中的搜索框