How to use API V2 to submit new data

Alternatively, if you’re familiar with Typescript/Javascript (but honestly even if you’re not, give a try, the typing system guide you along the way) there is a kobo-sdk that abstract all the API complexity.

For instance:

  • No need to build XML body
  • No need to format data with nested structure according to begin_group
  • No need to find formhub/uuid
  • Add Attachments simply using a link

It looks like this

import {KoboClient} from 'kobo-sdk'

const sdk = new KoboClient({
  urlv1: 'https://kc.kobotoolbox.org',
  urlv2: 'https://kf.kobotoolbox.org',
  token: '<YOUR PRIVATE TOKEN>',
})

await sdk.v1.submission.submitXml({
  formId: '<form_id>',
  data: {
    question_name_type_text: 'answer',
    question_name_type_integer_variant1: 1,
    question_name_type_select_multiple: 'option1 option2',
    question_name_begin_repeat: [
      {question_name: 'answer1'},
      {
        question_name: 'answer2',
        question_name_nested_repeat: [{question_name: 'answer'}],
      },
    ],
  },
})

Hope it helps!