How do I connect my external API to Watson Assistant?

When you're building your chatbot it's not uncommon to need to connect it to an external API. Whether that's combining menu items and ingredient lists, spitting out weather information, or even playing back your favorite music there's always a place for an external API. IBM's Watson has neat and simple tools that make connecting your Watson bot to an external API simple. Today Elite is here to show you how in just a few simple steps but it is crucial to note before we start that Watson can only use an external API if the call and callback are in JSON format.

  1. Log in to your IBM cloud.
  2. Choose your service and launch tool.
  3. Choose your desired assistant.
  4. Choose your desired dialog skill.

Now that you're logged in and ready to begin, let's go through the steps on actually connecting your API.

  1. Connecting your API link to Watson assistant
  2. Open the options tab on the left-hand side and click on webhooks. Place in your API URL.

  3. Create intents & dialog nodes for your API
  4. For this, we are using breakfast and lunch as intents which we have set up to trigger when someone asks the bot what's for either breakfast or lunch.

  5. Switching on your Webhook
  6. Open up your desired dialog node that you would like to set up directly to your API, here we are using our Breakfast and Lunch nodes. At the top in the upper right-hand corner select customize, find the webhooks section and switch it to on, then apply.

  7. Calling back your API info in the dialog node
  8. Once your webhook is turned on you'll need to type in a simple phrase to get your assistant to respond with your API information (in this case either a breakfast or lunch menu item.) In the "respond with" section you'll need to use the phrase: $webhook_result_1.(key) In this case, ours will look like this: $ where .food is the key.

  9. Try it out
  10. Don't be shy, try it out can be found in the upper right-hand corner, or you can test it out directly.

After completing these steps your bot will be connected to your external API. Going off of the image from Step 5 we can see that asking Ellie "What's for breakfast?" she now responds with "eggs" straight from our api without having to put it directly into Watson dialog.