[ckan-dev] Using CKAN's API via PHP.

Henrik Aagaard Jørgensen henrikaagaardjorgensen at gmail.com
Mon Sep 29 07:52:59 UTC 2014


Hello everyone,

I'm trying to use CKAN's API via PHP.

I'm using cURL and are allowed if the dataset is not private. But when
trying to access a private dataset I get access denied.

CKAN is version 2.2 with datastore installed.

Running this code fails with response from the CKAN API with
"{'permissions': ['Not authorized to read resource.']}":

-----

$sql = 'SELECT * FROM "656eedf2-8648-442d-90fa-4500fc49eb4a"';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "
http://localhost/api/action/datastore_search_sql");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('sql' => $sql)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Authorization'array(' =>
'b5256727-2711-4ac5-9009-cfc155ec13a2'));
$response = curl_exec($ch);
curl_close($ch);

var_dump(json_decode($response));

-----

When I use the code on public datasets it works. The API-key I'm using is
the same as the user who created it, and I'm able to see it via the web
interface.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140929/230325b7/attachment-0002.html>


More information about the ckan-dev mailing list