Socket
Book a DemoInstallSign in
Socket

kobo-sdk

Package Overview
Dependencies
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kobo-sdk

A TypeScript SDK for seamlessly interacting with the [KoboToolbox](https://www.kobotoolbox.org/) API, abstracting its complexities. **Optimized for TypeScript, with full type definitions.**

2.4.1
latest
npmnpm
Version published
Weekly downloads
30
-62.5%
Maintainers
3
Weekly downloads
 
Created
Source

Kobo-SDK npm

A TypeScript SDK for seamlessly interacting with the KoboToolbox API, abstracting its complexities. Optimized for TypeScript, with full type definitions.

Table of Contents

Installation

npm install kobo-sdk

Usage

Initialization

import {KoboClient} from 'kobo-sdk'

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

Constructor Parameters

ParameterRequiredDescription
urlv1Alias kc_url. KoboToolbox provides two API versions; this one is specifically used for submitting data to a form, as there is no equivalent endpoint in v2.
urlv2Alias kf_url.
tokenPrivate API token, available in your KoboToolbox account settings.
ApiClientClassUses Axios by default. This parameter allows for a custom HTTP client.
logLogs output to the console by default.

Kobo Servers Index

ServerV1 (kc)V2 (kf)
EUhttps://kc-eu.kobotoolbox.orghttps://eu.kobotoolbox.org
Globalhttps://kc.kobotoolbox.orghttps://kf.kobotoolbox.org
DRChttps://kc-kobo.drc.ngohttps://kobo.drc.ngo/

Insert New Submission

Only the question name (without the begin_group path) is used as a key when submitting data.
The Kobo API expects grouped questions in a nested structure, but this function automatically handles the formatting.
If submission fails, it retries up to 5 times by default, which can be adjusted using the retries parameter.

await sdk.v1.submission.submitXml({
  formId: 'aM29e4jscqujByADmvDLrr',
  attachments: [{
    name: 'filename as indicated in the answers',
    url: 'URL to the file. Altenarively you can use `path` instead of `url` to select a local file.',
  }],
  data: {
    question_text: 'answer',
    question_integer_variant1: 1,
    question_integer_variant2: '1',
    question_select_multiple: 'option1 option2',
    question_select_one: 'option1',
    question_begin_repeat: [
      {question: 'answer1'},
      {
        question: 'answer2',
        question_nested_repeat: [{question_nested: 'answer'}],
      },
    ],
  },
})

Update Submissions

Only the question name (without the begin_group path) is used as a key when submitting data. The Kobo API expects $xpath as a key, including begin_groups but this function automatically handles the formatting.

If submission fails, it retries up to 5 times by default, which can be adjusted using the retries parameter.

[!NOTE] The Kobo API fails if it receives too many updates in a short time, but this function automatically splits requests into smaller chunks and queues calls, ensuring updates are throttled at a pace the Kobo API can handle.

await sdk.v2.submission.update({
  formId: 'aM29e4jscqujByADmvDLrr',
  submissionIds: ['1', '2'],
  data: {
    question_text: 'New answer',
    question_select_multiple: 'option1 option2 option3',
  },
})

Fetch Submissions

Supports filtering _submission_time by range, limit, and offset.
The Kobo API limits responses to 30,000 submissions per request to prevent timeouts, but this function automatically splits API calls into chunks and merges results, allowing retrieval of any number of submissions seamlessly.

sdk.v2.submission.get({
  formId: 'aM29e4jscqujByADmvDLrr',
  filters: {
    start: new Date(2024, 0, 1),
    end: new Date(2024, 0, 1),
    offset: 10,
    limit: 5e4,
  }
})

[!IMPORTANT] The function removes paths from keys and extracts answers from metadata. To retrieve the raw API response, use sdk.v2.submission.getRaw instead.

Get form permissions

const form = await sdk.v2.form.get('aM29e4jscqujByADmvDLrr')
const permissions = sdk.v2.form.getPermissionSummary(form)
// > [{userName: 'user1', permissions: ['add_submissions delete_submissions manage_asset validate_submissions view_asset view_submissions']}]

Under-the-Hood Features Summary

Submission

  • Implements the /v1/submission.xml endpoint, as JSON submissions cause bugs.
  • Automatically retrieves formhub/uuid.
  • Generates instanceID.
  • Formats the request body to match Kobo's complex nested structure.
  • Supports automatic retries.

Update

  • Controls update pacing to prevent server rejection.
  • Formats the request body using $xpath as keys.

Fetching

  • Manages data reconciliation when fetching over 30,000 submissions.
  • Provides a simple API for start and end query parameters.

TypeScript Support

We highly recommend using this SDK with TypeScript instead of JavaScript for full type support and to save yourself from unnecessary frustration. If you're not a developer or unfamiliar with TypeScript, don’t worry, the type system will guide you along the way.

autocomplete-parameters.png autocomplete-response.png

Contributing

Contributions are welcome! Feel free to submit a PR or open an issue.

FAQs

Package last updated on 23 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.