Teneo Developers

Convert a Composer bot

Create an integration

Integrations are a reusable set of scripts that can be written once and used many times within flows throughout the solution. Most commonly, they are used to connect to external services. Now it is time to create an integration in order to make an HTTP request to the OpenWeather Weather API.

  1. Open the 'Solution' tab in the solution's main window and select 'Resources'.
  2. Navigate to 'Integration' at the top.
  3. Click the 'Add' button to create an integration.
  4. Give your integration a name, like Weather, and then click on the back arrow to edit the integration.
  5. Give the default method a name, like Get weather.
  6. In the Inputs section, click on add. This will allow us to send information to the integration when we call it.
  7. Name the input parameter postalCode.
  8. In the Outputs section, add new outputs with the names responseCode, resultCelsius, resultCity, resultCountry, resultFahrenheit, resultIcon, and resultWeather.
  9. Paste the following script into the Executon Script section of the Default Method:

groovy

1import groovy.json.JsonSlurper;
2
3def url = 'http://api.openweathermap.org/data/2.5/weather?zip=' + postalCode + ',us&appid=' + APIKey;
4
5def get = new URL(url).openConnection();
6def getRC = get.getResponseCode();
7
8if (getRC.equals(200)) {
9	def result = get.getInputStream().getText();
10	def parser = new JsonSlurper();
11	def json = parser.parseText(result);
12
13	def weather = json.weather.main[0].toLowerCase();
14	def kelvin = json.main.temp;
15	def celsius = Math.round(kelvin-273.15)
16	def fahrenheit = Math.round((celsius * 9/5) + 32)
17	def city = json.name;
18	def country = json.sys.country;
19	def icon = json.weather.icon[0];
20
21	responseCode = getRC;
22	resultWeather = weather;
23	resultCelsius = celsius;
24	resultFahrenheit = fahrenheit;
25	resultCity = city;
26	resultCountry = country;
27	resultIcon = icon;
28}
29
  1. Save and close the integration.

Next page
Store API key
Was this page helpful?