The JOTFORM Library is an importable library containing functions to connect, authenticate, and interact with the Jotform Adapter component, like our other Applications adapters, API. This library is used in the Jotform Adapter. The library uses simple core concepts and common design patterns to ensure they are extensible and easy to understand.
Here is how it works:
...
You can get very creative - checkout the Jotform API
...
documentation for all the available methods.
When imported into projects, typically only the JOTFORMclient module needs to be required in order to create the client and access the API methods.
Code Block | ||
---|---|---|
| ||
local S = JOTFORMclient{key=component.fields().Key} |
How it works:
Use the Translator’s built in help to review how to use each function:
Expand | |||||
---|---|---|---|---|---|
| |||||
JOTFORMclient creates the Slack Jotform adapter framework. JOTFORMgetSubmission and JOTFORMcustom modules are defined in a metatable as methods and set to the S object. The API key passed to JOTFORMclient is assigned to the new S table so that it can be used by the methods. If the API key is not passed, a “Missing key“ error is thrown.
Concepts used:
|
Expand | |||||
---|---|---|---|---|---|
| |||||
The COUNT Library is used to get the data from the custom field called “Since”. JOTFORMgetSubmission is called, passing in the Form ID configured in custom fields, and a “created at“ filter value for the timestamp of the last poll.
Concepts used:
| |||||
Expand | |||||
| |||||
| to make the '/form/<form_id>/submissions' API call. The Filter parameter is set to a timestamp of the last poll. |||||
Code Block | |||||
|
| %m-%d %H:%M:%S',C.filter)
local Filter = {}
Filter["created_at:gt"] = Since
local P = {}
P.filter = json.serialize{data=Filter,compact=true}
iguana.logInfo('Retrieving form submissions from '..Since)
return T:custom{api='/form/'..C.form_id..'/submissions', parameters=P, live=C.live}
end
return JOTFORMgetSubmission||||
Expand | |||||
| |||||
JOTFORMcustom is a helper function designed to handle different API requests with Jotform. It prepares the API Key to be passed as a parameter for authentication and assigns the url endpoint prepared by JOTFORMgetSubmission. net.http.get{} is used to send the request to Jotform. The response is parsed and either the response or error response is returned. code |
Expand | ||
---|---|---|
| ||
local function JOTFORMcustom(T, C)
local P = C.parameters or {}
P.apiKey = T.key
local Url = "https://api.jotform.com"..C.api
trace(Headers, Url, C.parameters)
local R, Code = net.http.get{url=Url, headers=Headers,parameters=P, live=C.live}
if (C.live ~= true) then
return "notlive"
end
R = json.parse{data=R}
if Code ~= 200 then
return false, R
else
return true, R
end
end
return JOTFORMcustom |
Expand | |||||
---|---|---|---|---|---|
| |||||
If JOTFORMgetSubmission returns a successful response with submission content, then the “Since“ custom field used to create the polling filter is set to a Unix Epoch time integer using JOTFORMtimestampToEpoch (see next section). For each submission content entry, the content is serialized as a string and queued. The component is then set to run every 5 minutes.
Concepts used: |
Expand | |||
---|---|---|---|
| |||
JOTFORMgetSubmission is passed the client object and the table of defined parameters. JOTFORMgetSubmission formats the required endpoint and parameters to call JOTFORMcustom to make the '/form/<form_id>/submissions' API call. The Filter parameter is set to a timestamp of the last poll. |
Expand | |||||
---|---|---|---|---|---|
| |||||
JOTFORMdateConversion contains the JOTFORMtimestampToEpoch() function which takes a timestamp in UTC and converts it to Unix Epoch Time. Using pattern matching, the timestamp pieces (year month, day, hour, min, sec) are isolated and used to create the equivalent Unix Epoch integer to replace the “Since“ custom field.
Concepts used: |
Thats it! This component is intentionally designed to enable you to easily extend its functionality to meet your exact workflow needs.
...