[ckan-discuss] New Zealand CKAN Instance - API errors

Rufus Pollock rufus.pollock at okfn.org
Mon Jul 26 15:17:19 BST 2010

On 23 July 2010 11:11, Glen Barnes <glen at opengovt.org.nz> wrote:
> I've been working on getting the existing NZ catalogue migrated over to CKAN and have come across some issues. About 10 records were created via the API but now I can't seem to create any new ones. I've pasted a Gist with the connections I am making:
> http://gist.github.com/487236
> I basically do a get on the resource to see if it exists and if it doesn't then do a post to the api with the new package data (note I have deleted my key from the gist) for security reasons. I can do a get on an existing package "GET /api/2/rest/package/test"   and this returns the right data but posting won't work - It gives a 500 server error.

If posting a *new* package I believe you need to post to the
"register" api not a package API: /api/2/rest/package

Posting to /api/2/rest/package/test implies an UPDATE not a CREATE.
This could be made clearer in the docs I think. Also the error should
not be a 500 but a 404 (not found) or perhaps 501 Not Implemented.

So, to summarize:
  1. Do a GET on /api/2/rest/package/{name} (you could also do a
search or even get a list of all packages to start with by doing GET
on /api/2/package or /api/1/package is you want the name)
  2. POST to /api/2/rest/package with your new package (if it does not exist)

> Any ideas of what could be wrong? Also when it 404's on the API it gives you back an HTML 404 page. Shouldn't it give you back a JSON formatted 404 instead?

What would you mean by a JSON-formatted 404? {'status': 404}. I
believe the page does return the right status header (if not that is a
bug!) and the html page is just a convenience.


> Any pointers most appreciated.
> Thanks,
> Glen
> _______________________________________________
> ckan-discuss mailing list
> ckan-discuss at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-discuss

Open Knowledge Foundation
Promoting Open Knowledge in a Digital Age
http://www.okfn.org/ - http://blog.okfn.org/

More information about the ckan-discuss mailing list