By querying REST web services you can retrieve specific data within your form.
In my example, I will be gathering weather data from a REST web service. The data that appears will depend on the zip code I enter into my form. For example, if I query zip code 98101, weather data for Seattle will appear in my form.
What you need:
- A Textbox: This value will relay back to the web service and gather the specified data. This is where I’ll type a zip code.
- A Custom Button: Putting a rule on this button will enable it to query my web service.
- A Repeating Section: The Repeating Section will hold the data. Each time I query a different zip code, the data will appear here. In my example, I will have multiple Textboxes that will each have different data appear.
- An API: To retrieve data from your REST web service, you will need an API key.
HOW TO QUERY A REST WEB SERVICE
Add the three controls mentioned above: Textbox, Custom Button, and Repeating Section.
Add a query data source.
In the right panel, select Query and +DATA SOURCE.
Select Web Service (REST) and NEXT to prompt the data source wizard. Enter a name for your query (RESTWeather), paste the API URL, and CONNECT. You can also choose to query data on load, or Attach credentials if desired.
Create a rule on the Custom Button. To do this, select the Custom Button, and Logic > NEW RULE in the left panel.
This rule will read; If the Textbox value is changed, use that value in the Rest URL to retrieve the specific data.
IF All of the below; Condition: textbox1, is not blank
DO THIS; Action: Change REST URL From RESTWeather(query data source name). Then enter your API key, and replace the changeable value to textbox1. For my example, if I change the Textbox zipcode value from Seattle to Chicago, the weather data will update to show conditions in Chicago when I query using the Custom Button.
Edit the repeating section data source: Select the Repeating Section > Logic > EDIT DATA SOURCE.
All you do here is select the data source info and specify what information to retrieve in the controls within the repeating section.
Now that your REST query is set up, you can query values and see your Repeating Section update with different data.
NOTE: you can also give the query Textbox (in this case the zip code) a default value, and have the REST query on load. By doing this, the form would query the default Textbox value when the form is opened on the user’s device. The picture under Step 2 shows the checkbox for the query data on load option.