Our larger corporate clients have asked us for a way to be able to exchange Zingtree data with other applications. Some customers want to send data from a Zingtree session to another application, or include data from another application in Zingtree.
Zingtree’s data exchange feature make use of Webhooks with JSON formatted data. (A lot of the tools we utilize work the same way.)
To demonstrate how to send and receive data from your decision trees, we will walk through how to build a simple tree that asks for a USA zip code, and then shows the city and state for that zip code inside the tree.
We will send data to a custom webhook we built, which takes a parameter of a zip code. It returns a JSON structure with the city and state info. Here’s an example of the webhook in use:
If you click the link above, you’ll see these results:
The PHP source code for the webhook URL is here.
The variables #city#, #state# and #state_abbreviation# will now be usable by Zingtree. So to show the city, just enter #city# into the content area of any node.
Here’s a summary of how this works:
- Add the webhook to your organization’s apps.
- Include a call to the webhook in a node. When the node is visited, the call is executed.
- Any JSON variables returned by the call become Zingtree variables.
Adding the Webhook:
- Go to Account > My Apps.
- Click the Webhook button under My Apps.
- Enter a name for the webhook, and the URL as shown:The URL is:
#zip# will receive the zip code variable entered by the end-user.
- Click Add Webhook. This makes the hook available to your trees.
Calling the Webhook when a node is visited:
- Go to Overview, and edit the node you want to trigger the webhook call.
- Under Send Message To, select Webhook: Zip Lookup.
The demo uses the free zippopotam.us postal code lookup service.