Skip to main content

surveycto@2.2.3

cursor(value, options)
fetchSubmissions(formId, options, callback)
request(path, params, callback)

This adaptor exports the following from common:

alterState()
chunk()
dataPath()
dataValue()
dateFns
field()
fields()
fn()
fnIf()
lastReferenceValue()
merge()
parseCsv()
sourceValue()

Functions

cursor

cursor(value, options) ⇒ Operation

Sets state.cursor to a SurveyCTO timestamp string (MMM dd, yyy h:mm:ss a). This supports natural language dates like now, today, yesterday, n hours ago, n days ago, and start, which will be converted into timestamp strings. See the usage guide at https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors

ParamTypeDescription
valueanythe cursor value. Usually an ISO date, natural language date, or page number
optionsobjectoptions to control the cursor.
options.keystringset the cursor key. Will persist through the whole run.
options.defaultValueanythe value to use if value is falsy
options.formatfunctioncustom formatter for the final cursor value

Example: Use a cursor from state if present, or else use the default value

cursor('today')
fetchSubmissions('test', { date: $.cursor });

fetchSubmissions

fetchSubmissions(formId, options, callback) ⇒ Operation

Fetch form submissions.

If a date filter is provided, it will be converted internally to the surveyCTO MMM dd, yyy h:mm:ss format (in UTC time).

ParamTypeDescription
formIdstringForm id
optionsFetchSubmissionOptionsForm submission date, format, status parameters
callbackfunction(Optional) Callback function

Example: Fetch all form submissions

fetchSubmissions('test');

Example: With SurveyCTO date format (UTC)

fetchSubmissions('test', { date: 'Apr 18, 2024 6:26:21 AM' });

Example: Using a rolling cursor

cursor((state) => state.cursor, { defaultValue: 'today' });
fetchSubmissions('test', { date: (state) => state.cursor, format: 'csv' });
cursor('now');

Example: Formatting the results to CSV String

fetchSubmissions('test', { format: 'csv' });

Example: With reviewStatus filter

fetchSubmissions('test', { status: 'approved|rejected' });

Example: With a callback function

fetchSubmissions(
'test',
{
date: 'Apr 18, 2024 6:26:21 AM',
},
state => {
console.log('Hello from the callback!');
return state;
}
);

request

request(path, params, callback) ⇒ Operation

Make a request in SurveyCTO API

ParamTypeDescription
pathstringPath to resource
paramsRequestOptionsQuery, body and method parameters
callbackfunction(Optional) Callback function

Example

request("/anEndpoint", {
method: "POST",
query: { foo: "bar", a: 1 },
});

Interfaces

FetchSubmissionOptions

Options provided to fetchSubmissions()

Properties

NameTypeDefaultDescription
[date]string0Fetch only submissions from this timestamp. Acccepts SuvreyCTO date strings, unix and epoch timestamps, and ISO dates. By default, all submissions will be retrieved.
[format]string"json"Format the submission data type as csv or json.
[status]stringReview status. Can be either, approved, rejected, pending or combine eg `approved

RequestOptions

Options provided to request()

Properties

NameTypeDefaultDescription
[headers]objectAn object of headers parameters.
[body]objectBody data to append to the request.
[query]objectAn object of query parameters to be encoded into the URL.
[method]string"GET"The HTTP method to use.