Call an API
After configuring an API, you need to trigger the call and access the returned data.
There are two ways to trigger API calls:
- 1Auto fetch: Automatically calls the API on load or when dependencies change
- 2Workflow actions: Manually trigger the API from workflows
Using auto fetch
Auto fetch automatically calls your API without requiring manual triggers. This is particularly useful for data that should be loaded immediately when a component appears.
To enable auto fetch:
- 1Navigate to your API in the data panel
- 2Toggle Auto fetch on
- 3Optionally use a formula for conditional fetching
Using workflow actions
Workflow actions give you precise control over when APIs are called, typically in response to user interactions or other events.
To call an API from a workflow:
- 1Create or edit a workflow for an event
- 2Click + to add an action
- 3Under APIs, select your API
- 4(Optional) Specify any input values you want to override, as defined in the API
API example
The following example demonstrates how to implement a weather card that combines both API calling methods. It uses auto fetch to load weather data when the component mounts and provides a update button that manually triggers the API through a workflow action.
API inputs
API inputs let you customize parameters each time you call an API, giving you flexibility to reuse the same endpoint with different values depending on the context.
Define inputs for your API:
- 1Click + in the Inputs tab
- 2Set a name
- 3Set a default value, either static or dynamic using the fx button
When calling the API through a workflow action, all defined inputs become available for overriding.
Unlike test values which are only used during development, input values serve as actual default values when the API is called with auto-fetch enabled.
Handling API callbacks
Callbacks are events triggered by API responses, letting you execute specific workflows.
Available callbacks:
- 1On success: Triggered when the API call is successful
- 2On error: Triggered when the API call fails
- 3On message: Triggered when a message is received
Set up callback handling in the Events section of the API or workflow action.
Callback events on the API are executed just before the action-specific events.
The following example demonstrates how to configure and react to an API callback event.
Accessing API data
Once your API call completes, the resulting data is available for use in your application's logic and UI.
Access API response in the formula editor:
- 1In the formula editor, add a new node and select the API endpoint from the APIs section
- 2Select the data you want to use
Available API response data:
isLoading
: Indicates if the API call is in progressdata
: Contains the successful API response bodyerror
: Holds error information if the API call failedresponse
: Provides HTTP response details:status
: HTTP status codeheaders
: Response headersperformance
: Performance metrics
Use isLoading
to manage UI states during data fetching (e.g. showing loading indicators, disabling interactions).