[Building Sakai] Using REST to get a list of sites
Shaun Donovan
shaund at teqcle.co.za
Mon Feb 16 23:52:52 PST 2015
Hi all.
I am trying to use Sakai's RESTFul services to get a list of sites
available to the administrator. I am using Sakai 10.3, and PHP with
Httpful library.
The documentation on http://localhost:8080/direct/describe states:
Entity Collection URL: GET /site <http://localhost:8080/direct/site>
(xml <http://localhost:8080/direct/site.xml>) (json
<http://localhost:8080/direct/site.json>) (html
<http://localhost:8080/direct/site.html>) (form
<http://localhost:8080/direct/site.form>)
Response Code Details: 200 plus data; 404 if not found, 406 if format
unavailable
Retrieves the list of all sites that the current user can access. Supply
a value for '_limit' to specify how many sites should be returned. Note
that there is a system maximum that will override a specified value if
it is larger than allowed. Supply a value for '_start' to page through
results in multiple requests. For example, with 42 sites, requests with
'_start' = 1, '_limit' = 50 and then '_start' = 51, '_limit' = 50 could
be used to retrieve the first batch of 42 sites and the second being
empty would signify the end of available results.
I am writing my code in PHP, so, I log in to Sakai using /direct/session
and retrieve the session id. I then run my request against /direct/site
and I add the _start and _limit as in :
GET
/direct/site.json?_sessionId=a1317f61-2db6-4108-b01d-e9270d4747e7&_start=1&_limit=20
This returns a JSON object with 19 sites in it.
I then submit:
GET
/direct/site.json?_sessionId=a1317f61-2db6-4108-b01d-e9270d4747e7&_start=21&_limit=20
This returns a JSON object with a single site.
Third submission is:
GET
/direct/site.json?_sessionId=a1317f61-2db6-4108-b01d-e9270d4747e7&_start=41&_limit=20
This returns a JSON object with a single entry.
My code is looking for count($response->body->site_collection) == 0 to
indicate that there are no more sites to get. If i set _limit to a low
number (20), I only find 33 sites, but if I set _limit to a high number
(800), I find 293 sites. This indicates that on a low _limit, I can get
an empty result even when there are more sites to find.
My question is therefore twofold:
What is the system maximum spoken about in describe?
Is there a better way to check for the end of the list?
Any help is appreciated.
Kind Regards.
Shaun Donovan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/sakai-dev/attachments/20150217/b230ff5b/attachment.html
More information about the sakai-dev
mailing list