'Chainlink External Adapter with RapidAPI [Request failed with 500 Internal Server Error]
I followed chainlink tutorial to build an external adapter. Unfortunately, after hours of debugging, my EA is still not working, flashing the 500 internal server error.
HTTP/1.1 500 Internal Server Error
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 186
ETag: W/"ba-z+FLILUhYUEw92/8nbj21rBflVg"
Date: Wed, 11 May 2022 05:05:45 GMT
Connection: close
{
"jobRunID": 0,
"status": "errored",
"error": {
"error": {
"name": "AdapterError",
"message": {
"error": {
"name": "AdapterError",
"message": "Required parameter not supplied: base"
}
}
}
},
"statusCode": 500
}
The API I am trying to fetch is AeroDataBox API (from RapidAPI marketplace). We need 2 params: flight number (AC1309) and date (2022-05-09).
This is the RapidAPI code snippet recommendation:
const fetch = require('node-fetch');
const url = 'https://aerodatabox.p.rapidapi.com/flights/number/AC1039/2022-05-09';
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Host': 'aerodatabox.p.rapidapi.com',
'X-RapidAPI-Key': 'db0eaaf009msh506491d3d299ed8p10a8d4jsnc705a04d3eb2'
}
};
fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
This is the snippet of my code in the index.js:
const customParams = {
flightNumber: ['flightNumber'],
date: ['yyyy-mm-dd'],
endpoint: false
}
const createRequest = (input, callback) => {
const validator = new Validator(callback, input, customParams)
const jobRunID = validator.validated.id
const API_KEY = process.env.API_KEY
const flightNumber = validator.validated.data.flightNumber
const date = validator.validated.data.date
const url = `https://aerodatabox.p.rapidapi.com/flights/number/${flightNumber}/${date}`
const params = {
flightNumber,
date
}
const headers = {
'X-RapidAPI-Host': 'aerodatabox.p.rapidapi.com',
'X-RapidAPI-Key': `${API_KEY}`
}
}
const config = {
url,
params,
headers
}
Requester.request(config, customError)
.then(response => {
callback(response.status, Requester.success(jobRunID, response.data))
})
.catch(error => {
callback(500, Requester.errored(jobRunID, error))
})
This is my curl command:
curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "flightNumber": "AC1309", "date": "2022-05-09" } }'
I don't know what I am missing? Thank you for your help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
