It's now well known that InfoPath 2010 has the built-in ability to query REST webservices. But did you know that you can use qRules' QueryData command to query REST data even if you or your users are still using InfoPath 2007? Here's a simple example of how you can do this.
The below tutorial uses Yahoo's Geocode API as an example of a REST webservice to look up geographical detail using a zip code. It assumes you are working with an InfoPath form that already has qRules 2.4 or higher injected into it.
-
Open the data connection wizard to add a new data connection.
-
Indicate that it is a connection to Receive data and click Next.
-
Select XML document as the source for the data and click Next.
-
-
Select Access the data from the specified location and click Next.
-
Name the data source Zip Code Lookup, uncheck Automatically retrieve data when the form is opened, and click Finish.
-
You should now have a new data source with a structure that looks like this:

-
Now let's add a few controls to the form. Add a new field called
ZipCode to your main data source and create a textbox with this. Add a button underneath that and change its label to say
Query. Also, drag the
City and
State fields from the
Zip Code Lookup data source and create textboxes or expression boxes with them. These will display the data returned from the webservice. Your form should look like something this when you are done:

-
Now it's time to add the query logic. Create a new rule on the
Query button that does the following:
Set the
Command field in the
QdabraRules data source to the value of the formula:
concat("QueryData /dsname=Zip Code Lookup /url=http://where.yahooapis.com/geocode?country=us&postal=", ZipCode)

Note that this formula constructs a URL to the Yahoo webservice, concatenating in a field value from the form for the zip code.
-
Preview the form, enter a valid zip code in the textbox and click the
Query button. The query results should be displayed down below:

That's it!