I’m having trouble forming the HTTP request in a correct format as expected for submitting data using the KOBO REST API. I’m trying to this from.net (C#). Could someone please assist me with a simple example of a code snippet of what this would look like?
I’m having trouble forming the HTTP request in a correct format as expected for submitting data using the KOBO REST API. I’m trying to this from.net (C#). Could someone please assist me with a simple example of a code snippet of what this would look like?
Thank you!
Hussein
–
You received this message because you are subscribed to the Google Groups “Kobo Users” group.
Thanks for your reply. I’ve managed to submit data via CSV files as follows:
var client = new RestClient("https://kc.kobotoolbox.org/api/v1/forms/{pk}/csv_import");
client.Authenticator = new HttpBasicAuthenticator("user_name", "password");
client.AddDefaultUrlSegment("pk", "31045");
string file_path = Server.MapPath("~/myform.csv");
var request = new RestRequest(Method.POST);
request.AddFile("csv_file", file_path);
IRestResponse response = client.Execute(request);
but I still find it difficult with either JSON or XML. I think the main challenge is figuring out how exactly the XML file should be structured or how the JSON should be structured.
Thanks!
···
On Wednesday, December 9, 2015 at 6:56:31 PM UTC+3, Tino Kreutzer wrote:
Hi Hussein,
Are you trying to POST an XML or a JSON submission? There are some examples in our API documentation.
I’m having trouble forming the HTTP request in a correct format as expected for submitting data using the KOBO REST API. I’m trying to this from.net (C#). Could someone please assist me with a simple example of a code snippet of what this would look like?
Thank you!
Hussein
–
You received this message because you are subscribed to the Google Groups “Kobo Users” group.
Thanks for your reply. I’ve managed to submit data via CSV files as follows:
var client = new RestClient("[https://kc.kobotoolbox.org/api/v1/forms/{pk}/csv_import](https://kc.kobotoolbox.org/api/v1/forms/%7Bpk%7D/csv_import)");
client.Authenticator = new HttpBasicAuthenticator("user_name", "password");
client.AddDefaultUrlSegment("pk", "31045");
string file_path = Server.MapPath("~/myform.csv");
var request = new RestRequest(Method.POST);
request.AddFile("csv_file", file_path);
IRestResponse response = client.Execute(request);
but I still find it difficult with either JSON or XML. I think the main challenge is figuring out how exactly the XML file should be structured or how the JSON should be structured.
Thanks!
On Wednesday, December 9, 2015 at 6:56:31 PM UTC+3, Tino Kreutzer wrote:
Hi Hussein,
Are you trying to POST an XML or a JSON submission? There are some examples in our API documentation.
I’m having trouble forming the HTTP request in a correct format as expected for submitting data using the KOBO REST API. I’m trying to this from.net (C#). Could someone please assist me with a simple example of a code snippet of what this would look like?
Thank you!
Hussein
–
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-us...@googlegroups.com.
Thanks for your reply. I’ve managed to submit data via CSV files as follows:
var client = new RestClient("[https://kc.kobotoolbox.org/api/v1/forms/{pk}/csv_import](https://kc.kobotoolbox.org/api/v1/forms/%7Bpk%7D/csv_import)");
client.Authenticator = new HttpBasicAuthenticator("user_name", "password");
client.AddDefaultUrlSegment("pk", "31045");
string file_path = Server.MapPath("~/myform.csv");
var request = new RestRequest(Method.POST);
request.AddFile("csv_file", file_path);
IRestResponse response = client.Execute(request);
but I still find it difficult with either JSON or XML. I think the main challenge is figuring out how exactly the XML file should be structured or how the JSON should be structured.
Thanks!
On Wednesday, December 9, 2015 at 6:56:31 PM UTC+3, Tino Kreutzer wrote:
Hi Hussein,
Are you trying to POST an XML or a JSON submission? There are some examples in our API documentation.
I’m having trouble forming the HTTP request in a correct format as expected for submitting data using the KOBO REST API. I’m trying to this from.net (C#). Could someone please assist me with a simple example of a code snippet of what this would look like?
Thank you!
Hussein
–
You received this message because you are subscribed to the Google Groups “Kobo Users” group.
I’m having some trouble submitting data programmatically using JSON. I imagine it is because I’m not constructing the JSON properly. Here’s my script for a form that has a single question “Name_Entered”:
Hi @ks_1, unfortunately submitting data with JSON can be unpredictable — I’m also battling. I would recommend rather using XML as that’s how we handle it on the backend. You can see how we handled submission duplication here.
It isn’t pretty, but I adapted what I did there to try and meet your current need. You’ll just need to adjust things to make it work for you and likely use Python’s xml.etree library as I did to programmatically update the xml tree. In this example I’ve just used the submission’s XML structure as a template (you can see that if you navigate to /api/v2/assets/{asset_uid}/data.xml)
Note that if you look at the network tab in your browser dev tools while submitting data through Enketo, the request data will give you a rough idea how to do what you’re wanting.