This is essentially a solution to the problem I posted regarding downloading submissions as an xls file.
So I explore the API docs and i found this example: curl -X GET 'https://kc.kobotoolbox.org/api/v1/data/22845?query={"date": {"gt$": "2014-09-29T01:02:03+0000"}}'
I came across this post that clarified this example:
So the greater than operator is not gt$ but $gt and to get submissions past a certain date, you need to compare it with the _submission_time column.
So here is my code in c#, still raw, but it gets the work done. This effectively reduces the download size because you can formulate your query so it does not contain submissions that were already downloaded.
The string variable the_response contains the json string containing submissions that satisfy the condition _submission_time > 2020-08-19
using (var httpClient = new HttpClient())
{
string api_call = "https://kc.kobotoolbox.org/api/v1/data/[form_id]?format=json&query={\"_submission_time\" : {\"$gt\": \"2020-08-19\"}}";
using (var request = new HttpRequestMessage(new HttpMethod("GET"), api_call))
{
var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("user_name:password"));
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");
var response = await httpClient.SendAsync(request);
var bytes = await response.Content.ReadAsByteArrayAsync();
Encoding encoding = Encoding.GetEncoding("utf-8");
string the_response = encoding.GetString(bytes, 0, bytes.Length);
}
}
The c# code above works and gives me a json string representing an object hierarchy 3 levels deep.
Due to the naming convention used by kobotoolbox, a lot of the property names have embedded slashes in them like the example below. "fishing_vessel_group/search_value":"m", "soak_time_group/soaktime_tracking_group/gps":"LAM"
I need to remove the embedded slashes from the property names before feeding the json string into a parser that creates the objects that represent one or more submissions.
I would like to ask if anyone already has a solution to this problem. I prefer a regex solution where it finds strings containing slashes that are enclosed in quotes. What I propose is to replace the slash with a safe character like 2 successive underscores so that the property name becomes legal in c#.
HI @mizanvai
Thank you for your message. Could you please provide more information about the problem? Kindly provide screenshots alongside a detailed narration of what part of the data is missing.