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

Henrik Aagaard Jørgensen henrikaagaardjorgensen at gmail.com
Mon Sep 29 08:13:38 UTC 2014


Sorry for the wring copy-paste, this is my actual code:

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

Using your code gives me the same result. I've tried in several PHP forums,
including StackOverflow, but they refer to the API I'm calling because
usually the authorization header is something like 'Authorization: Basic
XYZ'.

2014-09-29 10:09 GMT+02:00 Ross Jones <ross at servercode.co.uk>:

> 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
>
>
>
> _______________________________________________
> 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/14d73eff/attachment-0003.html>


More information about the ckan-dev mailing list