KoBo API examples, using new KPI endpoints

Hi @maric.vladimir
We do not have an approach for importing data via API into KoBoToolbox . This is not currently supported on the platform. However we can see if other users have been able to do this on their end.

Stephane

@tomgr, yes, you can manipulate REST Services through the API. Take a look at https://kf.kobotoolbox.org/api/v2/assets/[Your Asset UID]/hooks/.

1 Like

The format of the XML output from the /data endpoint seems odd.

https://kobo.humanitarianresponse.info/api/v2/assets/[AssetID]/data.xml

Produces the below, as expected

<?xml version="1.0" encoding="UTF-8" ?><root><count>2</count><next></next><previous></previous><results><item>

But within each item tag is an encoded string of text representing XML, rather than containing the XML directly:

>     &lt;aexRbJgmrYG3gwJExgGpan xmlns:jr=&quot;http://openrosa.org/javarosa&quot; xmlns:odk=&quot;http://www.opendatakit.org/xforms&quot; xmlns:orx=&quot;http://openrosa.org/xforms&quot; id=&quot;aexRbJgmrYG3gwJExgGpan&quot; version=&quot;vu67i8YdEnNeYNmv7QH5oC&quot;&gt;
>               &lt;formhub&gt;
>                 &lt;uuid&gt;e13d16e21e1f458386737162dd307795&lt;/uuid&gt;
>               &lt;/formhub&gt;
>               &lt;start&gt;2020-01-06T15:51:02.023-00:00&lt;/start&gt;

So we can’t easily access the data itself using XSL processing offered by the tool we use to consume the data.

Is this deliberate?

In addition to the above, we also see occasional additional XML declarations within the output XML. Can this be fixed? Is this forum the only way of flagging issues with the XML V2 API?

Hello @AndrewM,
Thank you for feedback.
Actually, there is no official support for XML format for data endpoint. The recommended format is JSON.
Having that said, we are aware that the XML rendering is not perfect and an issue was opened for that.
https://github.com/kobotoolbox/kpi/issues/2393.
We do not have an ETA for that, though.

3 Likes

@AndrewM You could have a look at this option, which I’ve used to import data from Excel:

1 Like

Did you ever figure out how to create users via the API endpoint? I’ve tried, but keep getting at 500 error.

1 Like

Also x-reffing back to the UNHCR KoBo API usage documentation - exaomples of how to query submissions using the API, to return only submissions meeting specific criteria (rather than always getting all of them).’

2 Likes

hey everyone is there any way to integrate kobo with odoo modules?

Welcome to the community, @sulimandanish! Would you mind providing more details on odoo modules, so that the community should be able to help you if possible?

sir i wana integrate my odoo modules such as activity_extension module or program management module so that user can enter data and that data is available on data base as kobotollbox works but the form data is also available on our database

Hey man, I wanted to say you are a lifesaver. How the hell was I supposed to know how to upload a .xlsx file to /api/v2/imports. I couldn’t find it in the documentation anyway.

Cheers!

For me this worked:
https://kf.kobotoolbox.org/api/v2/assets/aYPF4AcaS2kRtrustmeamfake/data.json

1 Like

Welcome to the community, @jicuby! Thank you for sharing this with the entire community and making the community rich with documentation :clap: Expecting the same in the upcoming days too :heart:

Thank you for your response
sir basically i want to integrate kobotoolbox with ERP system to fetch submitted data from kobotoolbox forms and deploy them on ERP system but i am not able to fetch data from kobo API’s on postman once i got data from API’s it will be easy to deploy on ERP.Sir basically there is no any proper documentation through which i can fetch data from API’s in json format. Sir if possible kindly guide.Thank You Sir…

hi guys I want to access kobo toolbox data in my web site and I try to access in JavaScript ajax

the code is

$.ajax({
                 type: 'Get',
                 url: 'https://kf.kobotoolbox.org/assets/a7GG9SXYtLTCS4FLm4mjjP/submissions/?format=json',
                 dataType : 'jsonp',
                 success: function(data) {
                  console.log(data);
                 },
                 error: function(data) {
                     console.log("error");
                 }
              });

https://kf.kobotoolbox.org/assets/a7GG9SXYtLTCS4FLm4mjjP/submissions/?format=json <---- when I write this URL on web browser it retrieve JSON data but in JavaScript i can’t access it

I have the same issue. Do you find a solution? Thanks!

Thanks @jnm for sharing this.
Could anyone advise how to use partial_submissions:“make partial actions on submitted data for asset for specific users” .
I tried many times but couldn’t develop the correct code.

best

@Josh i am struggling with the redeployment api, after i pull my version_id and make the PATCH request i keep getting a 500 server error. here is a snippet of my code, what could be the issue

const formData = new URLSearchParams();
formData.append('version_id', versionId);
                formData.append('active', true.toString());
                    return fetch('https://kf.kobotoolbox.org/api/v2/assets/aHZVifqvuT9dbi7YKYJhw7/deployment/', {
                        method: 'PATCH',
                        headers: {
                          'Accept': 'application/json',
                          'Authorization': 'Token <My Token>',
                        },
                        body: formData,
                      })
                        .then(response => response.json())
                        .then(data => {
                          console.log('Redeployed successfully');
                        })
                        .catch(error => console.error('Error:', error));