Some data field is missing while data call by API

this is my kobo survey from
https://drive.google.com/file/d/1dCYKbGmVajhx0p0qBwBgzHCFH_IJXhns/view?usp=sharing

this is my menually downloaded data


and this is my api json data

in there so many data field is missing

my api is

using (var httpClient = new HttpClient())
            {
                string api_call = "------";
                using (var request = new HttpRequestMessage(new HttpMethod("GET"), api_call))
                {
                    var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("username: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);
                    //var members = JsonConvert.DeserializeObject<List<ShelterJsonInput>>(the_response);
                    //_customService.SendShelterDataList(members);                 
                }
            }

thanks in advance
mizan

Have you gone through the post discussed previously:

1 Like

@mizanvai,

I think your form is working correctly.

What i noticed is that only those questions in 9. Item Information Group:
that have responses are included in the JSON text. If the questions have no replies, they are not part of the JSON text.

Try to fill up another form and this time answer all the questions in 9. Item Information Group:. I think that this time, the JSON text will be complete.

Hope this helps,
Raffy

.

3 Likes

Thank you for your kind support.
My problem is solved

@raffy_m and @Kal_Lam

2 Likes

Thank you @raffy_m for helping out @mizanvai :clap: Expecting the same in the upcoming days as well :star_struck:

2 Likes

@raffy_m and @Kal_Lam brother i am in a problem while I am trying to get data using API, in the survey form has one repeated group, if I download excel there two sheets in one file there have a relationship between sheets, but API returns only data without indexing or relation with two data model.

thanks in advanced

@mizanvai
In Excel, the parent - child relationship is clear because child objects (the repeated group) which are found in the second sheet share the same ID number of the parent which is in the first sheet.

When using the API to get a JSON text of your objects, it is only the parent that gets the ID, in this case the _uuid, and the child objects do not get any. The reason is that the relationship is already implied in the way the JSON text is written.

The JSON text that is returned by kobotoolbox, if it contains repeating groups, has this pattern:

Pls take note that comments in the form of // are not allowed.

{

”_uuid”:”c8b9563f-8809-4e04-9e0c-cb2422576a68”,
"question_1":"reply 1",
"question_2":"reply 2",

//repeating group
"question_3/repeat_group":
[
//1st item of group
{"question_3/repeat_group/repeat_question_1":"reply_repeat_1", "question_3/repeat_group/repeat_question_2":"reply_repeat_2"},

//2nd item of group
{"question_3/repeat_group/repeat_question_1":"reply_repeat_3", "question_3/repeat_group/repeat_question_2":"reply_repeat_4"}
]

}

You can tell the objects under question_3/repeat_group are embedded because they are inside an array. We can tell they belong to an array because of the bracket symbols - [ and ] . So any objects inside the braces are child objects, thus establishing a relation.

reply_repeat_1 and reply_repeat_2 are the first items of the repeating group. Notice that this group is inside curly braces - { and }

reply_repeat_3 and reply_repeat_4 are the second items of the repeating group. The second groups is also inside curly braces.

If you want to save the data in the JSON text to a database, then you have to create an identifier and assign it to the parent. The same identifier is also assigned to the child objects thus establishing the relationship. This is how I did it in my application. I did not try to find out if there is a better way to do this.

Hope this helps

2 Likes