Chainlink 外部适配器向 Spotify 发出 API 调用时出现问题

Trouble with Chainlink External Adapter making an API call to Spotify

我从 Javascript External Adapter Template from Chainlink 制作了一个外部适配器,尝试使用 Spotify API 到 return 艺术家数据的客户端凭证流,文档如下。 https://developer.spotify.com/documentation/general/guides/authorization-guide/#client-credentials-flow https://developer.spotify.com/console/get-artist/

而且我可以通过 Axios 使用此代码进行调用

但是当我尝试通过外部适配器 运行 相同的调用时,它也使用 Axios 进行 API 调用,我收到此错误。

这是来自 index.js

的外部适配器的主要代码片段

const customParams = {
  artist: [''],
  
  endpoint: false
}

const createRequest = (input, callback) => {
  // The Validator helps you validate the Chainlink request data

  const apiID = process.env.API_ID
  const apiKey = process.env.API_KEY

  let token = 'BQDlkzka093OuR4tL7XyaI-Tag4R166FQGBSogBP6hEBxhsCjH8XfMRqs_apKFk0T87FGIrwPtT1bkuGCeE';


  const validator = new Validator(callback, input, customParams)
  const jobRunID = validator.validated.id
  const endpoint = validator.validated.data.endpoint
  const artistID = validator.validated.data.artist.toUpperCase()
  const url = `https://api.spotify.com/v1/artists/${artistID}`

  const params = {
    artistID
  }

  // curl -X "GET" "https://api.spotify.com/v1/artists/5K4W6rqBFWDnAN6FQUkS6x" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer authtoken" 

  
  // This is where you would add method and headers
  // you can add method like GET or POST and add it to the config
  // The default is GET requests
  // method = 'get' 
  // headers = 'headers.....'
  const head = {
    'Accept' : 'application/json',
    'Content-Type' : 'application/json',
    'Authorization' : 'Bearer ' + token
  }
 
  const config = {
    url,
    headers: head
  }
  console.log("config:", config)

这是我在终端中 运行 用于传递 Spotify 艺术家 ID

的命令

curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "": "5K4W6rqBFWDnAN6FQUkS6x"} }'

-编辑-

只是为了证明代码并非完全错误,我可以通过外部适配器调用此 url https://jsonplaceholder.typicode.com/posts/5,并使用此命令传入 5。

curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "": "5"} }'

问题出在这行,使艺术家 ID 全部大写。

const artistID = validator.validated.data.artist.toUpperCase() // Changed this 
const artistID = validator.validated.data.artist // To this