Bonus Exercise 1: Integrating via APIs

Duration: 45 minutes

In this bonus exercise, we will use a real webservice API to update our list of airports which we previously imported via an excel spreadsheet. This will ensure that the locations all remain up to date with some additional data fields for tracking.

If you noticed in exercise 1, when we imported the Airports from the excel sheet, the Lat and Lon data is empty, we will go ahead and fix that.

relative

Note: This session will require you to use a 3rd party API service to get data. Your personal data will be required to sign up to this service. If you are not comfortable with exposing this data, skip this exercise or let your instructor know.

Part 1: Create an Integration Action

  1. Go to https://airlabs.co/ and click Sign Up

    relative

  2. Fill in the relevant details to sign up for an account

  3. Verify your account with the email sent to the email address sent to your email account

    relative

  4. Sign in to your airlabs account on the next page

  5. Click Copy next to API Key

    relative

  6. Paste your copied API Key somewhere that you are able to retrieve later

  7. Click Documentation, then Airports

  8. Quickly read through this API documentation, notice that the API request has already been populated for you - We will rebuild this

  9. Navigate back to your main ServiceNow interface, and search and click Action Designer under All

    relative

  10. You are brough to the Flow Designer interface

  11. Click the New button on the top right, then click Action

    relative

  12. In the pop-up, enter Get Airport Details under Action name. For description, enter Calls the Airlabs API to retrieve airport details

    relative

  13. Click Submit

  14. Click Create Input

  15. Under Label, enter IATA Code, then press enter

    relative

  16. Click on the + icon in between Inputs and Error Evaluation on the left sidebar

    relative

  17. In the pop-up box, scroll down and click REST

    relative

  18. Change Connection to Define Connection Inline

  19. Copy this URL and paste it under Base URL:
    https://airlabs.co/api/v9

  20. Enter /airports under Resource Path

  21. Click on the + icon for Query Parameters

  22. Enter api_key under Name, then paste your previously copied API Key under Value

    1. Click on the + icon for Query Parameters
  23. Enter iata_code under Name, then drag and drop the IATA Code data pill on the right sidebar onto the Value field

  24. Click on the + icon for Headers

  25. Enter User-Agent under Name, and XXXXXX under Value

  26. Your form should now look like this:

    relative

  27. Click Save at the top right

  28. Click Test at the top right

  29. Enter SIN under the IATA Code field, then click Run Test

  30. Click Your test has finished running. View the action execution details.

    relative

  31. The new tab shows every step of the execution so far. Expand Steps and scroll down to the line that shows Response Body

  32. Click on the corresponding value and copy the entire block of text

    relative

  33. Navigate back the the main Action Get Aiport Details tab

  34. Close the pop-up

  35. Click on the + icon on the left sidebar after REST step

    relative

  36. Scroll down and click JSON Parser

  37. Drag and drop the Response Body data pill from the right sidebar onto the Source data field

  38. Paste what you copied onto the main body

  39. Toggle the Structured Payload View

  40. Click Generate Target

  41. The Target on the right should be generated

  42. Here are all the steps in sequence:

    relative

  43. Click Outputs on the left sidebar

  44. Click Create Output

    relative

  45. In the new row, change Label to Output, Name to output and Type to Array.Object

    relative

  46. Click Exit Edit Mode

  47. On the right sidebar, expand root under JSON Parser Step

  48. Drag and drop the response data pill onto the Output Value field

  49. Click Publish on the top right

    relative

  50. Click Test

  51. Enter BKK and run test, then view execution details

  52. Ensure that the Output is defined, and when clicking on it you see a result similar to what is shown below

    relative

  53. You’ve completed integration! Now let’s use it in a workflow


Part 2: Using our integration action

  1. Close all the pop-up boxes and click on the + tab

  2. Click Flow

    relative

  3. Under Flow name, enter Update airport information

  4. Set Run As to System User

    relative

  5. Click Submit

  6. Click Add a trigger, then select Daily under date. This will run this workflow everyday

    relative

  7. Click Done

  8. Click Add an Action, Flow Logic, or Subflow

  9. Click Action

  10. Search and select Look Up Records - Pay special attention to selecting Look Up Records and not Look Up Record

    relative

  11. Search and select Airport under Table

  12. Click Done

  13. Click Add an Action, Flow Logic, or Subflow

  14. Click Flow Logic

  15. Click For Each

    relative

  16. Drag and drop the Airport Records data pill from the right sidebar onto the Items field

  17. Click the + icon under the For Each Item in step

    relative

  18. Click Action

  19. Search and click Get Airport Details (this was the API integration action we just created)

    relative

  20. Expand Airport Record on the left sidebar under the 2 - For Each section

  21. Drag and drop the Code data pill onto the IATA Code field

  22. Click Done

    relative

  23. Add a new For Each Flow Logic under Get Airport Details

  24. Drag and drop the Output data pill onto Items

  25. Click the + under the new For Each Item in step

    relative

  26. Click Action, then search and select Update Record

  27. Drag and drop the Airport Record data pill under 2 - For Each onto the Record field

  28. Click + Add field value

  29. Search and select Lat, expand the response_object data pill under 4 - For Each

  30. Drag and drop the lat data pill on the empty field

  31. Click + Add field value

  32. Search and select Lon, expand the response_object data pill under 4 - For Each

  33. Drag and drop the lng data pill on the empty field

  34. Refer to the full animation below:

    relative

  35. Click Done

  36. Click Activate on the top right

  37. Click Test

  38. Click Run Test

  39. This will take a few minutes to run as we have 24 airports to update. Once done, click Your test has finished running. View the flow execution details.

  40. Review the execution, take some time to expand each step to understand what has happened in this flow

    relative

  41. Go back to App Engine Studio and preview the Airport table

    relative

  42. This will open in a new tab, verify that all the Lat and Lon fields are now populated

    relative

This flow should now run everyday to update the latitude and longitude of each airport in your table. In a real life scenario, you could do so much more with the API, but this is just an example to show you the possibilites. For example, you could integrate with a complex booking API like Amadeus, and your users could search for flights and book flights and hotels directly from your custom application!


Back to top

Shao Wei Tan, 22 Aug 2022, based on the Utah release.