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

Ross Jones ross at servercode.co.uk
Mon Sep 29 08:09:17 UTC 2014


Hi,

Your problem is this line:

> curl_setopt($ch, CURLOPT_HTTPHEADER, Authorization'array(' => 'b5256727-2711-4ac5-9009-cfc155ec13a2'));

try something like the following (expanded for clarity) …

$headers = array();
$headers[] = 'Authorization: ' . $myapikey

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


Ross.

p.s. this is really a PHP question, rather than a CKAN question ;) 


On 29 Sep 2014, at 08:52, Henrik Aagaard Jørgensen <henrikaagaardjorgensen at gmail.com> wrote:

> 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.
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140929/a1a0aae4/attachment-0003.html>


More information about the ckan-dev mailing list