Advanced parsing
To allow you to perform GET and POST requests, we have added an advanced parsing option to both the pre-parser and the device definition parser. When the option is turned on you have access to a fully functional HTTP GET/POST tool, which can be used to send data or make request to other applications.
Advanced parsing features are disabled by default. Contact your Collactr Partner to have it enabled for you.
Asynchronous requests
The parserUtils GET/POST functions return a promise, so you can use the “await” keyword to wait for their response. Doing so, you will need to mark the “preParser” and “parsePayload” function with the “async” keyword. Using those functions, you can post whatever data you like.
That means the parsePayload/preParse function:
const parsePayload = (payloadStr) => {
...
}
needs to be changed to:
const parsePayload = async (payloadStr) => {
...
}
In the definition parser you can decode the payload or pick what data you wish to post elsewhere. You can also make multiple GET/POST calls in the same parser.
Handling Responses
When a GET/POST request is sent, it will (depending on the type of request) return the following data.
- isError // if an HTTP error occurred
- status // the HTTP status returned
- data // Any data returned
- response // More details about the HTTP response (headers, etc)
Limitations
Our gateway only allows a parser to run for up to 10 seconds. This means slow GET/POST requests might cause your parser to be terminated before it can finish processing. Another limitation is that we don’t allow external NodeJS libraries to be used. Due to security concerns, the parsers are sandboxed with only the bare bones in functionality.