How to configure calls to external APIs to fetch data.
På denne siden:
Call external APIs to fetch data
NOTE: Currently, only open APIs (that do not require authentication) are supported for this funcitonality.
External APIs can be used to populate data in the form from external sources. There is currently implemented support for two types of values fetched from external APIs: Single value and List of values.
APIs fetching a single value
This type of API potentially takes some input from a field in the form, submits this to the API as a parameter, and returns a single value in response. The connection can be configured to populate a set field in the form with this fetched value. An example of this is the Bring poststed API, which takes a postal code as input and returns the postal area.
APIs fetching a list of values
This type of APIs works in a similar way to code lists. It potentially takes some input from a field in the form, submits this to the API as a parameter, and returns a list of values in response. The connection can be configured to populate the options of a form component that can have multiple values (f.ex. a dropdown list, radio buttons, checkboxes). An example of this is the SSB kommuneliste API, which returns a list of all the municipalities in Norway defined in a configured time interval.
|Bring poststed||Fetches the name of the Norwegian postal area based on input of corresponding postal code||Single value|
|SSB kommuneliste||Fetches a list of all Norwegian municipalities, as defined in a set time interval||List of values|
Configure API connection
- Add any form components that might be needed for the input/output values for the selected API. Make sure that the form components are connected to fields in the data model.
- Select Legg til tilkobling under API-tilkoblinger from the left-hand menu in the GUI editor.
- Select Eksternt API.
- Select API from the list of available APIs.
- Add client parameters,if any (ClientParam) - These are any input parameters that are populated from selected form data.
- Add an example value to test the API call
- Select data model field that corresponds to the data model field connected to the input field.
- Add any additional parameters required by the API (MetaParam) - this is input required by the API that does not come from the form data.
- Test the API call by clicking Fetch from API using parameters.
- This will test that the call is working with the selected parameters, using the example value as input.
- The response from the test will be shown in the textbox under API Response
- Select Add new mapping to map the response to a field in the form.
- Select which object from the response that should be used to populate the field (the API may return more than one object in response).
- Select data model field that corresponds to the data model field connected to the field that will show the output from the API.
- Note that this should be a component type that supports lists (ex. dropdown, checkboxes, radiobuttons, etc.) for APIs returning a list of values.
- Save the configuration by clicking Lagre.
- Test that it works by typing in a valid input value in the input field, and see that the output field is populated with the result of the API call.