Upload CSV files automatically to KoboToolBox Media Files

Hi All,

  1. General Inquiry:
    I’m facing an issue uploading CSV data to KoboToolbox using a Google Apps Script. I’m getting the “code 404 - Not Found” error message. Can someone assist me in resolving this issue?

  2. Technical Details:

  • I have ensured that the KoboToolbox API URL I’m using is correct, and the form ID matches. Is there something specific I should check in the script configuration or my KoboToolbox project?
  1. Recent Updates:
  • Are there any recent updates to the KoboToolbox API that might affect my script? I want to ensure that I am following the latest best practices.
  1. Check Server Response:
  • I’ve added the muteHttpExceptions: true option to the script to see the complete server response. Are there any further indications in the response that could help me identify the source of the problem?
  1. KoboToolbox Support:
  • Is there any guidance from KoboToolbox regarding handling the 404 error I’m experiencing? Are there additional steps I should take to address this issue?

Here is the javascript code in Apps Script of Gdrive.

function uploadCSVToKobo() {
var folderId = ‘YOUR_GOOGLE_DRIVE_FOLDER_ID’; // Ganti dengan ID folder Google Drive Anda
var folder = DriveApp.getFolderById(folderId);
var files = folder.getFiles();

var apiUrl = ‘https://kf.kobotoolbox.org/api/v2/assets/YOUR_FORM_ID/submissions/’;

while (files.hasNext()) {
var file = files.next();

// Proses hanya file CSV
if (file.getMimeType() === 'text/csv' || file.getMimeType() === 'application/vnd.ms-excel') {
  var csvData = file.getBlob().getDataAsString();

  var options = {
    'method' : 'post',
    'contentType': 'application/json',
    'headers': {
      'Authorization': 'Token YOUR_KOBO_API_TOKEN', // Ganti dengan token API KoboToolbox Anda
      'Content-Type': 'multipart/form-data'
    },
    'payload': {
      'data': csvData
    }
  };

  var response = UrlFetchApp.fetch(apiUrl, options);
  Logger.log(response.getContentText());
}

}
}

Welcome to the community, @andis! Maybe these posts discussed previously should help you solve your issue:

and …

Hi @Kal_Lam, unfortunately these post can not help me. Is there any other solution? where I can ask and get the answer?

Hi All,

Is there anyway to automatically upload CSV files to KoboToolBox Media Files?

Thanks.