CKAN api

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

CKAN api

#1

Postby Steve James » Fri Oct 14, 2016 12:09 pm

Hi, I am trying to call a CKAN api package_create http://docs.ckan.org/en/latest/api/

By the looks of things I need to pass a raw json value instead of form data.

I've managed to make further progress when using the Chrome Postman extension but when using Ebase I get errors.

Code: Select all

var d = {
	"name":"my_dataset_name",
	"notes":"A long description of my dataset",
	"owner_org":"organisation"
	}

var response = services.rest.post(u, null, headers, d);
When this gets passed it looks like variable d is converted into a series of key pairs as I get the following error

Code: Select all

Bad request - JSON Error: Error decoding JSON data. Error: JSONDecodeError('Expecting value: line 1 column 1 (char 0)',) JSON data extracted from the request: 'notes=A long description of my dataset&name=my_dataset_name&owner_org=organisation'
I've also tried passing d in the body but CKAN is then not happy that it's a string.

How can I pass the raw value in using Ebase? Or has anyone any experience of calling CKAN api from in Ebase?
Thanks
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Fri Oct 14, 2016 12:36 pm

Normally you would serialize the JSON object and pass it as the body i.e.

Code: Select all

var response = services.rest.post(u, JSON.stringify(d), headers); 
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#3

Postby Steve James » Fri Oct 14, 2016 12:40 pm

Thanks Jon, I wasn't totally clear but I've tried that.

I get
Bad request - JSON Error: Could not extract request body data: Bad content type: '; charset="utf-8"'

Thanks
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#4

Postby Jon » Fri Oct 14, 2016 1:22 pm

Have you set the content type as a header:

Code: Select all

var headers = {"Content-Type":"application/json"};
var response = services.rest.post(u, JSON.stringify(d), headers); 
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

#5

Postby Steve James » Fri Oct 14, 2016 1:53 pm

thanks Jon, long week, TGI Friday.
0 x


Who is online

Users browsing this forum: No registered users and 75 guests