API Response Events
This article assumes that you are already familiar with sensor events. If not, please refer to this guide.
API response event is a new type of external event, similar to sensor and datasource events. These can be set up anywhere where an API call is happening.
- It can be an action bound to a sensor event.
- It can be a widget click type on the Other tab on some widgets, in the Interaction (previously: Jump) section. (Where you would choose jump to or popup.)
- It can also be a submit action of a submit button.
API response events are unique for every API call, but they can be copied and pasted between instances.
On the top of the window, you will need to set the main property name. You should design your API in a way that the response will always have this property.
Then, in the main property value column you can set up the different possible values of this always present property, that you want to handle.
If an action is not final, multiple actions with the same main property value will be executed, until one final is not triggered.
If you turn on use regular expressions for values, similar to sensor events, all values will be treated as regular expessions and it will be checked whether the the value provided in the main property name field matches one of these.
The only difference is with interact widget, because Api response actions can interact with not only interactive widgets, but also with any widget that can be bound to a datasource. Mostly useful with text and image widgets.
For example, you can create a system with an RFID sensor and an API that sends back the details of the selected product or employee or guest, etc. In this case, you would set up your sensor action similar to this example. Your API will be called as “POST” and the body will contain 3 fields: “id”, “event” and “value”. Depending on your sensor, either event or value will hold the RFID being scanned. Your API should respond with an object that contains a field, such as “RFID_RESPONSE_CODE” and all the fields for the different widgets on the details page. It could be “name”, “image_name”, “price” or “room number”, etc. Don’t forget to turn OFF final for all these actions, so all the widgets can receive their values.
Your Api response actions would look similar to this. You widgets can be positioned and formatted like any normal widgets. This will only change their value. Images work the same way as data bound images, so any value that would be valid in a data field bound to an image is valid here as well.