Kobo api without attachment

Hello there i have a problem when i call api for getting data it’s taking to long time to response.
note every submission have attachment in this form. is there any option to call api without api Please me know
this is my api

string api_call = “https://kc.humanitarianresponse.info/api/v1/data/…?format=json”;

            using (var request = new HttpRequestMessage(new HttpMethod("GET"), api_call))
            {
                var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("user:pass"));
                request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");
                HttpClient client = new HttpClient();
                client.Timeout = TimeSpan.FromMinutes(15);
                var response = await client.SendAsync(request);
                var bytes = await response.Content.ReadAsByteArrayAsync();
                Encoding encoding = Encoding.GetEncoding("utf-8");
                string the_response = encoding.GetString(bytes, 0, bytes.Length);
               
            }

@Kal_Lam brother any help for me please

1 Like

Pinging in @Josh for this issue.

thank you @Kal_Lam
i am waiting for @Josh
@stephanealoo any solution for me
or if there any like as only selected column will return.

thanks again

1 Like

Hi @mizanvai, sorry for the late response. You can try doing something like

# Using /api/v2
curl -X GET 'https://[kpi]/api/v2/assets/{asset_uid}/data/?fields=["field_1", "field_2"]&format=json'

# Using /api/v1
curl -X GET 'https://[kc]/api/v1/data/{id}/?fields=["field_1", "field_2"]&format=json'

There’s no parameter to exclude a field, so you will just have to list all the fields you want, excluding the ones you don’t.

Hope that helps.

2 Likes

thank you @Josh && @Kal_Lam

1 Like

Hi @Josh

I hope all is well.
Is it possible to just get the “attachments” list ? When I tried to use fields=[“_attachments”], I got an http 500 error code.
Thanks

Hi @dickoa, I don’t think _attachments is a valid filter field, but it still shouldn’t return a 500. I’ll raise this with the dev team :+1:

Edit: You can run this query if you include _uuid in the fields list: fields=["_attachments", "_uuid"] :tada:

1 Like

Thanks a lot @Josh for looking into it. I tried adding the uuid, but I still have the same server error.

I wanted to select that column to speed up the media retrieval via the API particularly for large projects, instead of pulling the complete JSON.

Hmm that’s interesting. It works on the Global server (kf.kobotoolbox.org) but I see that it still fails on the UNHCR server. I’ve informed the dev team about it :+1:

2 Likes

You’re right, I just created a dummy project with the Global server and it works.
I’ll also follow up internally.
Thanks again.

1 Like

Hello @dickoa, As a temporary workaround, you need to use ["_attachments","formhub/uuid","_uuid"].

2 Likes

This is perfect, it works like a charm.
Thanks again @Olivier

2 Likes