我正在尝试将Agile CRM集成到我的Symfony2应用程序中.
Agile提供了一个PHP库:https: //github.com/agilecrm/php-api
然而,它不是捆绑.
如何在我的应用程序中正确集成它?我应该在app.php或内核中添加一次require吗?或者,还有更好的方法?
在我的Phoenix应用程序中,我试图使用HTTPoison HTTP客户端(https://hexdocs.pm/httpoison/api-reference.html)向AgileCRM API发出发布请求。我能够使用cURL发出成功的请求,但是我尝试在Phoenix中复制它的尝试失败,出现401 UNAUTHORIZED错误。
我成功的cURL:
$ curl https://domain.agilecrm.com/dev/api/contacts/search/email \
-H "Accept: application/json" \
-d 'email_ids=["contact@test.com"]' \
-u admin@test.com:api_key
Run Code Online (Sandbox Code Playgroud)
返回状态200和请求的数据。
我失败的HTTPoison:
url = "https://domain.agilecrm.com/dev/api/contacts/search/email"
body = Poison.encode!(%{"body": "email_ids=['contact@test.com']"})
headers = [{"Accept", "application/json"}, {"Authorization", "admin@test.com:api_key"}]
response = HTTPoison.post!(url, body, headers)
IO.inspect response
Run Code Online (Sandbox Code Playgroud)
哪个返回
%HTTPoison.Response{body: "<html><head>\n<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n<title>401 UNAUTHORIZED</title>\n</head>\n<body text=#000000 bgcolor=#ffffff>\n<h1>Error: UNAUTHORIZED</h1>\n</body></html>\n",
headers: [{"X-TraceUrl", "/appstats/details?time=1509129565372&type=json"},
{"WWW-Authenticate", "Basic realm=\"agilecrm\""},
{"Content-Type", "text/html; charset=utf-8"},
{"X-Cloud-Trace-Context", "8de994n2tbu2o356891bc3e6"},
{"Date", "Fri, 27 Oct 2017 18:39:25 GMT"}, {"Server", "Google Frontend"},
{"Content-Length", "200"}],
request_url: "https://domain.agilecrm.com/dev/api/contacts/search/email", status_code: …Run Code Online (Sandbox Code Playgroud)