Implement External-Adapters

For the demo purpose, we will setup our external adapter to pull the data from weather api. Follow along this tutorial to understand how this works
Setting up external initiator requires following steps to be performed
  • Git clone the repository
  • cd & npm install
  • Include the API endpoint & Parse the payload
  • Run the server
Step 1 -
git clone
Step 2 -
cd weather_adapter
Step 3 -
npm install
Step 4 -
map the api endpoint

Requesting Data

When an external adapter receives a request from the Plugin node, the JSON payload will include the following objects:
  • data (guaranteed to be present but may be empty)
  • meta (optional, depends on job type)
  • responseURL (optional, will be supplied if job supports asynchronous callbacks)
  • id (optional, can be nice to use for EA logging to help debug job runs)
Returning Data
When the external adapter wants to return data immediately, it must include data in the returned JSON.
An example of the response data can look like:
"data": {
"result": "20.04"
Note - the external adapter that you are running, should be the same URL endpoint mapped in Bridge.
const { Requester } = require('@goplugin/external-adapter')
const customError = (data) => {
if (data.Response === 'Error') return true
return false
const customParams = {
endpoint: ['endpoint']
const createRequest = (input, callback) => {
const url = `http://<host>/api/${}`
const config = {
if (process.env.API_KEY) {
config.headers = {
Authorization: process.env.API_KEY
Requester.request(config, customError)
.then(response => {
if ( == "WindDirection") {
var resultData =[0]['windDirection'];
} else if ( == "Temperature") {
var resultData =[0]['tempC'];
} else if ( == "WindChill") {
var resultData =[0]['windChillC'];
} = resultData.toString();
const res = {
data: {
callback(response.status, Requester.success(, res));
.catch(error => {
callback(500, Requester.errored(, error))
module.exports.createRequest = createRequest
Let's see what's in "index.js"
  • We are importing 'external-adapter' from goplugin npm repo and importaing two methods such as Requester
  • importing "dotenv" module to access the .env file for sensitive info (API_KEY)
  • "customError" is a function to return either true or false if error occurs
  • "customParams" is a variable to declare custom parametes to pass on in URL - this can be customized accordingly
  • "createRequest" is the method actually doing heavy lifting.
    • URL is getting defined, since for weather node the endpoint is getting passed via smart contract the "endpoint" is accessed via ""
    • <host> to be replaced with respective domain name or ip address where we are fetching the data
    • api -> router name.. Again for our weather node, we have api as routername, for your case it can be different
    • config -> variable name to have url parm
    • Next, we are checking APIKEY if exists in env parm, else it will not be applied.. For authenticated API, you have to pass APIKEY
    • Requester.request will scan for the payload from api endpoint and customized the output .. In this example, we are checking ""
      • Note that, envCheck is a parameter we are passing via smart contract(Check weathernode)
      • Based on envCheck, the loop iterates and scan the value form output payload
      • Finally we are construing the response and return
When you run PM2 Start server.js, the server will by default run in port 5001 and just make sure the bridge is correctly pointed out to this port number.. For instance, this should be http://localhost:5001/