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

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

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

On Mon, Feb 8, 2016 at 3:05 AM, Joseph Luketelo joseph....@gmail.com wrote:

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

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.

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,

···

On Tuesday, February 9, 2016 at 3:12:42 AM UTC+3, Alex Dorey wrote:

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

On Mon, Feb 8, 2016 at 3:05 AM, Joseph Luketelo josep...@gmail.com wrote:

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

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.