# 8.2 Define an external data source

In this exercise, you'll create a custom external data source by making use of Adobe Journey Optimizer.

Login to Adobe Journey Optimizer by going to [Adobe Experience Cloud](https://experience.adobe.com). Click **Journey Optimizer**.

![ACOP](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-8daf9419deef804f9e816efc694a6fe4c6bef3fa%2Facophome.png?alt=media)

You'll be redirected to the **Home** view in Journey Optimizer. First, make sure you're using the correct sandbox. The sandbox to use is called `--aepSandboxId--`. To change from one sandbox to another, click on **PRODUCTION Prod (VA7)** and select the sandbox from the list. In this example, the sandbox is named **AEP Enablement FY22**. You'll then be in the **Home** view of your sandbox `--aepSandboxId--`.

![ACOP](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-df76386e3eebdceeccee0f3853f02cdec4b997f1%2Facoptriglp.png?alt=media)

In the left menu, scroll down and click **Configurations**. Next, click the **Manage** button under **Data Sources**.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-804b83bf995e0b05fa5e6920d054f557a100ba51%2Fmenudatasources.png?alt=media)

You'll then see the **Data Sources** list. Click **Create Data Source** to start adding your data source.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-fc5f5617352de2b74b5a8571a6204c937b5ff47a%2Fdshome.png?alt=media)

You'll see an empty data source popup.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-601acfb5050c3df7cd19445d7d1a2e750e568f8a%2Femptyds.png?alt=media)

Before you can start configuring this, you'll need an account with the **Open Weather Map** service. Follow these steps to create your account and get your API key.

Go to <https://openweathermap.org/>. On the homepage, click **Sign In**.

![WeatherMap](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-6b802ad8c92ea9de06e75500ec9a717952bcc57b%2Fowm.png?alt=media)

Click **Create an Account**.

![WeatherMap](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-86e55dbaa7190ab60a32660d8a50055eda530495%2Fowm1.png?alt=media)

Fill out the details.

![WeatherMap](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-fc88ee9907537c465e5660cd55c6572a961996f3%2Fowm2.png?alt=media)

Click **Create Account**.

![WeatherMap](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-718acb64bc97f9a60fab39fe646096927b973513%2Fowm3.png?alt=media)

You'll then be redirected to your Account Page.

![WeatherMap](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-7760f0aa461518a4c8cb4edad5b72a2a270f19f6%2Fowm4.png?alt=media)

In the menu, click **API Keys** to retrieve your API Key, which you'll need to setup your custom external data source.

![WeatherMap](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-a5d32573174ea337420f049b4ac728b89e6d3de7%2Fowm5.png?alt=media)

An **API Key** looks like this: `b2c4c36b6bb59c3458d6686b05311dc3`.

You can find the **API Documentation** for the **Current Weather** [here](https://openweathermap.org/current).

In our use-case, we'll implement the connection with Open Weather Map based on the city the customer is in.

![WeatherMap](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-18d011e599a026bd9fa1dafaaf1db7e90aed8dc2%2Fowm6.png?alt=media)

Go back to **Adobe Journey Optimizer**, to your empty **External Data Source** popup.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-601acfb5050c3df7cd19445d7d1a2e750e568f8a%2Femptyds.png?alt=media)

As a Name for the data source, use `--demoProfileLdap--WeatherApi`. In this example, the data source Name is `vangeluwWeatherApi` .

Set Description to: `Access to the Open Weather Map`.

The URL for the Open Weather Map API is: **<http://api.openweathermap.org/data/2.5/weather?units=metric>**

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-d2f609c839e84c1c94a0324c13cf8b9c28fd6f73%2Fdsname.png?alt=media)

Next, you need to select the Authentication to use.

Use these variables:

|   Field  | Value               |
| :------: | ------------------- |
|   Type   | **API key**         |
|   Name   | **APPID**           |
|   Value  | **your API Key**    |
| Location | **Query Parameter** |

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-744a0569d377ca0fc45d69754918e8c4bfbad886%2Fdsauth.png?alt=media)

Finally, you need to define a **FieldGroup**, which is basically the request you'll be sending to the Weather API. In our case, we want to use the name of the City to request the Current Weather for that City.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-4d8272ae1edaa8b8a7864b3e2b46ea4b64730a76%2Ffg.png?alt=media)

According to the Weather API Documentation, we need to send a parameter `q=City`.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-5fb9d6f2fd2740babf0e5f5b950834e918186f19%2Fowmapi.png?alt=media)

In order to match the expected API Request, configure your FieldGroup as follows:

{% hint style="warning" %}
The Field group name has to be unique, please use this naming convention: `--demoProfileLdap--WeatherByCity` so in this case, the name should be `vangeluwWeatherByCity`
{% endhint %}

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-d53df9409d446a7f0c0aaae76b3ab5e668fd157a%2Ffg1.png?alt=media)

For the Response Payload, you need to paste an example of the Response that will be sent by the Weather API.

You can find the expected API JSON Response on the API Documentation page [here](https://openweathermap.org/current).

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-67a418ad3011c62c4991b47d53e2058bf2394c2b%2Fowmapi1.png?alt=media)

Or you can copy the JSON Response from here:

```json
{"coord": { "lon": 139,"lat": 35},
  "weather": [
    {
      "id": 800,
      "main": "Clear",
      "description": "clear sky",
      "icon": "01n"
    }
  ],
  "base": "stations",
  "main": {
    "temp": 281.52,
    "feels_like": 278.99,
    "temp_min": 280.15,
    "temp_max": 283.71,
    "pressure": 1016,
    "humidity": 93
  },
  "wind": {
    "speed": 0.47,
    "deg": 107.538
  },
  "clouds": {
    "all": 2
  },
  "dt": 1560350192,
  "sys": {
    "type": 3,
    "id": 2019346,
    "message": 0.0065,
    "country": "JP",
    "sunrise": 1560281377,
    "sunset": 1560333478
  },
  "timezone": 32400,
  "id": 1851632,
  "name": "Shuzenji",
  "cod": 200
}
```

Copy the above JSON Response to your clipboard, then go to your custom data source configuration screen.

Click the **Edit Payload** icon.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-32571f35adab53ab31233b8c916c33bbcf87a9e4%2Fowmapi2.png?alt=media)

You'll see a popup where you now have to paste the above JSON Response.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-3f6f74b68da6c59f2397c09da1534ac4d0f94877%2Fowmapi3.png?alt=media)

Paste your JSON Response, after which you'll see this. Click **Save**.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-14822a08c9f323719c7523da4d46964240b22db2%2Fowmapi4.png?alt=media)

Your custom data source configuration is now complete. Scroll up and click **Save**.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-7d772e3d3c99e1d9d360a38dce7cd95b772b7bad%2Fdssave.png?alt=media)

Your data source has now been created successfully and is part of the **Data Sources** list.

![Demo](https://858372621-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpBC8bA57il8Sj47B7QPJ%2Fuploads%2Fgit-blob-0ad8f04208ec2e0d4c268c98fb3144737c047c7c%2Fdslist.png?alt=media)
