REST client for CollectiveAccess API
-
08-12-2019 - |
Question
I am trying to connect to webservice of a CollectiveAccess app (it is based on Zend framework) installed at http://localhost . According to documentation` one should authenticate like this:
http://localhost/ca5/service.php/iteminfo/ItemInfo/rest?method=auth&username=admin&password=123456
and after that, one can access API for instance like this:
http://localhost/service.php/iteminfo/ItemInfo/rest?method=getLabels&type=ca_objects&item_id=4&mode=all
That works for me if I paste URLs in a web browser but I cannot get it to work using HTTParty either basic_auth or digest_auth methods.
Solution
You need to authenticate as you are doing, but make sure HTTParty maintains the cookie that initial response returns for the life of your session. basic_auth and digest_auth are not used by CA - it's that session cookie it returns that is used to maintain session state.
OTHER TIPS
httpclient gem supports cookies out of the box and the following works fine with CollectiveAccess API:
require 'httpclient'
clnt = HTTPClient.new
clnt.set_cookie_store('/home/user/cookie.dat')
puts clnt.get('http://localhost/service.php/iteminfo/ItemInfo/rest?method=auth&username=administrator&password=12345').body
puts clnt.get('http://localhost/service.php/iteminfo/ItemInfo/rest?method=getLabels&type=ca_objects&item_id=4&mode=all').body