How to Import JSON data to existing form using KOBO REST API

460 views
Skip to first unread message

Joseph Luketelo

unread,
Feb 8, 2016, 3:05:50 AM2/8/16
to Kobo Users
I am having problems importing JSON data to existing form in https://kc.kobotoolbox.org.

Am able to import CSV and XML data to existing form using below code:

var client = new RestClient("https://kc.kobotoolbox.org/api/v1/forms/{pk}/csv_import"); client.Authenticator = new HttpBasicAuthenticator("user_name", "password"); client.AddDefaultUrlSegment("pk", "35545"); string file_path = Server.MapPath("~/form1.csv"); var request = new RestRequest(Method.POST); request.AddFile("csv_file", file_path); IRestResponse response = client.Execute(request);



var client = new RestClient("https://kc.kobotoolbox.org/api/v1/submissions");
client
.Authenticator = new HttpBasicAuthenticator("user_name", "password");
var request = new RestRequest(Method.POST);
string file_path = Server.MapPath("~/form1.xml");
request
.AddFile("xml_submission_file", targetPath);
IRestResponse response = client.Execute(request);



I want to achieve the same results but using JSON instead of CSV/XML.

Or if we have a good .NET converter that will convert my JSON file to XML/CSV in a format accepted by KOBO, that will be a solution too.

Thanks in advance.
Jose

Alex Dorey

unread,
Feb 8, 2016, 7:12:42 PM2/8/16
to kobo-...@googlegroups.com
Hi Jose,

Currently, the form submissions are based on the OpenRosa XForm submission API which specifies XML.
CSV imports are a workaround for accepting multiple submissions in one request. But JSON submissions are not supported.

We are looking at working this into the next version of the API, which is currently in the development stage, but that will not be available and documented on the production servers until April.

For now, I would suggest converting the data set to CSV if the submission data is simple (integers, decimals). Or, formatting the submissions as individual XML documents if CSV does not suffice.

-Alex

--
You received this message because you are subscribed to the Google Groups "Kobo Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kobo-users+...@googlegroups.com.
To post to this group, send email to kobo-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kobo-users.
For more options, visit https://groups.google.com/d/optout.


Message has been deleted

Joseph Luketelo

unread,
Feb 9, 2016, 6:24:25 AM2/9/16
to Kobo Users
Thanks Alex for the succinct explanation.

Looking forward to seeing the next version of the API with JSON support.

I will work with XML for now.

Thanks a lot.


Regards,
Reply all
Reply to author
Forward
0 new messages