[ckan-dev] Datasource and resource id - how do I create the initial resource in the datastore?

Henrik Korsgaard henrikkorsgaard at gmail.com
Wed May 15 06:34:31 UTC 2013


Thank you for the response Steve.

As I said, I have both created a resource via the action API
(package_create) and with a .csv file in the GUI. Both string id's and
their respective postgres id's, pulled from the ckan main db (not datastore
db). Each id  return (my emphasis):

{"help": "Adds a new table to the datastore.\n\n    The datastore_create
action allows a user to post JSON data to be\n    stored against a
resource. This endpoint also supports altering tables,\n    aliases and
indexes and bulk insertion. This endpoint can be called multiple\n    times
to ininially insert more data, add fields, change the aliases or indexes\n
   as well as the primary keys.\n\n    See :ref:`fields` and :ref:`records`
for details on how to lay out records.\n\n    :param resource_id: resource
id that the data is going to be stored against.\n    :type resource_id:
string\n    :param aliases: names for read only aliases of the resource.\n
   :type aliases: list or comma separated string\n    :param fields:
fields/columns and their extra metadata.\n    :type fields: list of
dictionaries\n    :param records: the data, eg: [{\"dob\": \"2005\",
\"some_stuff\": [\"a\", \"b\"]}]\n    :type records: list of dictionaries\n
   :param primary_key: fields that represent a unique key\n    :type
primary_key: list or comma separated string\n    :param indexes: indexes on
table\n    :type indexes: list or comma separated string\n\n    Please note
that setting the ``aliases``, ``indexes`` or ``primary_key`` replaces the
exising\n    aliases or constraints. Setting ``records`` appends the
provided records to the resource.\n\n    **Results:**\n\n    :returns: The
newly created data object.\n    :rtype: dictionary\n\n    See :ref:`fields`
and :ref:`records` for details on how to lay out records.\n\n    ", *"success":
false, "error": {"message": "Not found: Resource
\"fd74bf69-94ed-412e-bf9f-31b48269486b\" was not found.", "__type": "Not
Found Error"*}}


Here is the curl POST command:

curl -X POST http://127.0.0.1/api/3/action/datastore_create -H
"Authorization: my-api-key-here-ofc" -d '{"resource_id":
"fd74bf69-94ed-412e-bf9f-31b48269486b", "fields": [ {"id": "a"}, {"id":
"b"} ], "records": [ { "a": 1, "b": "xyz"}, {"a": 2, "b": "zzz"} ]}'

I have checked all the logs, tested with malformed queries and checked the
postgres permissions carefully by logging in write and read users,
respectively creating tables and selecting from tables via psql
commandline. Before I progress with writing a datastore client tool, I'd
like to be able to do the test.

Hope someone can help :)


On 14 May 2013 22:24, Lime, Steve D (MNIT) <Steve.Lime at state.mn.us> wrote:

>  I just went though this using git master so I'm guessing it's the same
> in 2.0. Key was creating a resource via the GUI first and then referencing
> its id via the API. It's definitely not intuitive but it's the way it
> works. For example, I created a data resource by uploading a CSV file then
> created a datastore associated with that CSV file. In my case I have the
> CSV file for download and then the datastore for visualization and API
> access (it's the same data). You could use a bogus URL or maybe reference a
> PDF file containing a data dictionary for the data resource as well.
>
>  You can get the data resource ID from either the PostgreSQL tables or
> from the GUI (you'll see the resource key in various URLs).
>
>  Steve
>
>  ------------------------------
> *From:* ckan-dev-bounces at lists.okfn.org [ckan-dev-bounces at lists.okfn.org]
> on behalf of Henrik Korsgaard [henrikkorsgaard at gmail.com]
> *Sent:* Tuesday, May 14, 2013 2:47 PM
> *To:* ckan-dev at lists.okfn.org
> *Subject:* [ckan-dev] Datasource and resource id - how do I create the
> initial resource in the datastore?
>
>   Hi all,
>
>  This is a very basic question and properly belong elsewhere, but here
> goes...
>
>  I have installed CKAN 2.0 from package install on Ubuntu 12.04, postgres
> 9.1.
>
>  In the final setup of the datastore, the guide provides a GET and a POST
> example via curl. I can do the GET, but I have a very basic question
> regarding the POST example. It says I have to provide a resource id of an
> existing CKAN datasource (in datastore?).
>
>  The examples in the final part of the datastore setup guide are a
> bit ambiguous, e.g. create a new resource  in datastore, up against an
> existing resource id, on a fresh (empty) install.
>
>  Now, I have created a resource through the CKAN site and with the action
> API (package_create), but the POST example does not recognise (Not Found
> Error) any IDs.
>
>  I have checked the apache log, the nginx log and the postgres log, no
> errors. Postgres write permissions are checked and double checked.
>
>  [Question] So, can anyone provide a short description of how to create a
> resource, obtain resource id and add create a resource in the datastore?
>
>  ...disclaimer: I might have overlooked something trivial in the various
> documentation, if so I am sorry :)
>
>  --
>  Med venlig hilsen - Best regards,
>
>  *Henrik Korsgaard*
> Phone: +45 22377114
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>
>


-- 
Med venlig hilsen - Best regards,

*Henrik Korsgaard*
Phone: +45 22377114
Office: CAVI 114b, Aarhus University

NB. I am slowly migrating my university related correspondence to my
official AU mail: korsgaard at cavi.au.dk - feel free to contact me at that
address if relevant.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130515/1e06447d/attachment-0001.html>


More information about the ckan-dev mailing list