{"id":19427125,"url":"https://github.com/anergictcell/survey_cto","last_synced_at":"2026-05-17T18:08:31.486Z","repository":{"id":57374987,"uuid":"73902969","full_name":"anergictcell/survey_cto","owner":"anergictcell","description":"A node module to download and parse form-data from SurveyCTO REST API. It converts wide-JSON to nested JSON Objects and takes care of type conversion","archived":false,"fork":false,"pushed_at":"2017-02-28T10:10:40.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-10T07:46:13.214Z","etag":null,"topics":["javascript","nodejs","nodejs-module","odk","odk-xforms","surveycto"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anergictcell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-16T09:10:13.000Z","updated_at":"2018-12-15T15:27:38.000Z","dependencies_parsed_at":"2022-09-05T13:21:03.683Z","dependency_job_id":null,"html_url":"https://github.com/anergictcell/survey_cto","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anergictcell/survey_cto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anergictcell%2Fsurvey_cto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anergictcell%2Fsurvey_cto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anergictcell%2Fsurvey_cto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anergictcell%2Fsurvey_cto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anergictcell","download_url":"https://codeload.github.com/anergictcell/survey_cto/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anergictcell%2Fsurvey_cto/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260427158,"owners_count":23007460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","nodejs","nodejs-module","odk","odk-xforms","surveycto"],"created_at":"2024-11-10T14:10:30.507Z","updated_at":"2026-05-17T18:08:26.461Z","avatar_url":"https://github.com/anergictcell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SurveyCTO - Download and parse form data from SurveyCTO\n\n## A node module for converting SurveuCTO's wide JSON data into structured objects\n\nSurveyCTO provides and API to automatically download form data. Unfortunately, the wide-JSON returned from their API is not ideal for some data analysis environment.\nThis module fills the gap by providing a simple API to download and parse the form data from your SurveyCTO surveys.\n\n## Table of contents\n\n- [Setup](#setup)\n- [Normal workflow](#normal-workflow)\n- [Simple download](#simple-download)\n- [Filter by date](#filter-by-date)\n- [Converting data](#converting-data)\n- [Defining repeats](#defining-repeats)\n- [Examples](#examples)\n- [API](#api)\n\n\n---\n\n\n## Setup\nThe SurveyCTO module works with global setting for the servername and authentification. Make sure to set them when first loading the module.\n```js\nvar surveyCTO = require('survey-cto')\nvar servername = \"myServerName\" // don't use the full domain, just your servername\nvar username = \"myUserName\"\nvar password = \"Pa55w0rd\"\nsurveycto.config(servername,username,password)\n//\n```\n\n## Normal workflow\n```js\nsurveyCTO\n  .addColumns([\"SubmissionDate\"],\"Date\")\n  .addColumns([\"instanceID\",\"KEY\"],\"String\")\n  .addColumns([\"repeatCount\"],\"Number\")\n  .addColumns([\"someBooleanField\"],\"Boolean\")\n  .accColumns([\"someMultipleSelect\"],\"Array\")\n  .addRepeat(\"myRepeat\")\n  .addToRepeat(\"myRepeat\",[\"repeatField\"],\"String\")\n  .addToRepeat(\"myRepeat\",[\"anotherRepeatField\"],\"Number\")\n  .formId('My_Test_form')\n  .getAndParse()\n  .then(function(data){\n    // do something with the data\n  })\n  .catch(function(err){\n    // log the error\n  })\n```\n\n## Simple download\nIf you want to simply download data without converting it:\n```js\nvar Request = require(\"./lib/Request.js\"),\nreq = new Request();\n\nreq.formId('My_Test_form')\n  .get()\n  .then(callback)\n  .catch(console.log)\n```\n`formId` sets the id of the form data to download.\n`get` returns a Promise containing the wide-JSON data.\nThe Promise is only resolved upon a `200` status code. All other status codes cause rejection.\n\n\n## Filter by date\nIf you only want to download form-data submitted after a specific date:\n```js\nvar Request = require(\"./lib/Request.js\"),\nreq = new Request();\n  \nreq.formId('My_Test_form')\n  .lastDate('2016-16-11 12:27:00 PM EAT')\n  .get()\n  ...\n```\n\n## Converting data\nBy default, all data in SurveyCTO's form-data is stored as `String` If you want to convert those strings to other datatypes:\n```js\nsurveyCTO.addColumns([\"columnName1\",\"columnName2\"],\"Number\") // converts all columnName1, columnName2 data into Numbers\n  .addColumns([\"columnName3\"],\"Date\") // converts all columnName3 data into Dates\n  .addColumns([\"columnName4\"],\"Array\") // splits the data of columnName4 into an Array\n  .addColumns([\"columnName5\"],\"Number-Array\") // splits the data of columnName5 into an Array and converts each element to a Number\n```\n\n## Defining repeats\nMerge data from the wide-JSON into a nested Object:\n```js\n// wideJson = {\"Meeting\":\"1\",\"name_1\":\"Bob\",\"name_2\":\"Alice\",\"name_3\":\"Paul\",\"age_1\":\"21\",\"age_2\":\"25\",\"age_3\":\"31\"}\nsurveyCTO.addRepeat(\"attendance\") // defines a new key with the name attendance\n  .addToRepeat(\"attendance\",[\"name\"],\"String\") // {\"Meeting\":\"1\",\"attendance\":[{\"name\":\"Bob\"},{\"name\":\"Alice\"},{\"name\":\"Paul\"}]}\n  .addToRepeat(\"attendance\",[\"age\"],\"Number\")  // {\"Meeting\":\"1\",\"attendance\":[{\"name\":\"Bob\",\"age\":21},{\"name\":\"Alice\",\"age\":25},{\"name\":\"Paul\",\"age\":31}]}\n```\n\n## Examples\nTBD\n\n## API\n#### \u003ci\u003esurveyCTO\u003c/i\u003e.\u003cb\u003eaddColumns\u003c/b\u003e(\u003ci\u003eArray\u003c/i\u003e,\u003ci\u003eType\u003c/i\u003e/\u003ci\u003eFunction\u003c/i\u003e)\nEnsures the data in the columns as defined in `Array` will be converted to type `Type` or via function `Function`.\n```js\nsurveyCTO\n  .addColumns([\"SubmissionDate\"],\"Date\")\n  .addColumns([\"instanceID\",\"KEY\"],\"String\")\n  .addColumns([\"doubleColumn\"],x =\u003e x*2)\n```\n\n#### \u003ci\u003esurveyCTO\u003c/i\u003e.\u003cb\u003eaddRepeat\u003c/b\u003e(\u003ci\u003ename\u003c/i\u003e)\nTells the parser to add a column with the given name to store repeat data in. The actual data to be stored within the repeat must be defined via \u003ci\u003esurveyCTO\u003c/i\u003e.\u003cb\u003eaddToRepeat\u003c/b\u003e.\n```js\nsurveyCTO\n  .addRepeat(\"myRepeatName\")\n```\n\n#### \u003ci\u003esurveyCTO\u003c/i\u003e.\u003cb\u003eaddToRepeat\u003c/b\u003e(\u003ci\u003ename\u003c/i\u003e,\u003ci\u003eArray\u003c/i\u003e,\u003ci\u003eType\u003c/i\u003e/\u003ci\u003eFunction\u003c/i\u003e)\nEnsures that the data from the columns as defined in `Array` will be converted to type `Type` or via function `Function` and stored in repeat `name`. Requires that the repeat has been defined via \u003ci\u003esurveyCTO\u003c/i\u003e.\u003cb\u003eaddRepeat\u003c/b\u003e.\n```js\nsurveyCTO\n  .addRepeat(\"myRepeatName\")\n  .addToRepeat(\"myRepeat\",[\"repeatField\"],\"String\")\n  .addToRepeat(\"myRepeat\",[\"anotherRepeatField\"],x=\u003ex*2)\n```\n\n#### \u003ci\u003esurveyCTO\u003c/i\u003e.\u003cb\u003erenameColumns\u003c/b\u003e(\u003ci\u003e{key:value}\u003c/i\u003e)\nConverts the names of columns from `key` to `value` during parsing.\n```js\nsurveyCTO\n  .renameColumns({\"oldName_1\":\"newNameOne\",\"anotherWeirdColumName\":\"shortname\"})\n```\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanergictcell%2Fsurvey_cto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanergictcell%2Fsurvey_cto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanergictcell%2Fsurvey_cto/lists"}