surveycto@2.1.1
Functions
The following functions are exported from the common adaptor:
- alterState()
- chunk()
- dataPath()
- dataValue()
- dateFns()
- field()
- fields()
- fn()
- lastReferenceValue()
- merge()
- parseCsv()
- sourceValue()
convertDate
convertDate
This function will attempt to convert any date representation into
a surveyCTO MMM dd, yyy h:mm:ss a
string.
Strings already in this format will be ignored, other strings will be parsed
by the Date constructor.
Number values should be epoch or unix timestamps and will be converted to strings
Param | Type | Description |
---|---|---|
date | * | a date in a string, number or Date format |
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
Param | Type | Description |
---|---|---|
value | any | the cursor value. Usually an ISO date, natural language date, or page number |
options | object | options to control the cursor. |
options.key | string | set the cursor key. Will persist through the whole run. |
options.defaultValue | any | the value to use if value is falsy |
options.format | function | custom 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 });
FetchSubmissionOptions
FetchSubmissionOptions : Object
Options provided to fetchSubmissions()
Properties
Name | Type | Default | Description |
---|---|---|---|
[date] | string | 0 | Fetch 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] | string | Review status. Can be either, approved , rejected , pending or combine eg `approved |
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).
Param | Type | Description |
---|---|---|
formId | string | Form id |
options | FetchSubmissionOptions | Form submission date, format, status parameters |
callback | function | (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
Param | Type | Description |
---|---|---|
path | string | Path to resource |
params | RequestOptions | Query, body and method parameters |
callback | function | (Optional) Callback function |
Example
request("/anEndpoint", {
method: "POST",
query: { foo: "bar", a: 1 },
});
RequestOptions
RequestOptions : Object
Options provided to request()
Properties
Name | Type | Default | Description |
---|---|---|---|
[headers] | object | An object of headers parameters. | |
[body] | object | Body data to append to the request. | |
[query] | object | An object of query parameters to be encoded into the URL. | |
[method] | string | "GET" | The HTTP method to use. |