0

I've built an external adapter for an API and deployed it as a cloud function on GCP. However, when I send a Curl command to the deployed external adapter, it returns an error 422. Below are the docs for the API I'm trying to reach, the code for the external adapter, and the curl command I am sending. I've been following this tutorial and using the template they provide here : https://blog.chain.link/build-and-use-external-adapters/ Can anyone spot where the problem is and how to fix it to get data back from the adapter?

API docs (I'm trying to reach the 'statistics' endpoint): https://shamba-gateway-staging-2ycmet71.ew.gateway.dev/geoapi/v1/docs

External Adapter code:

https://github.com/shambadynamic/meanExternalAdapter/blob/main/index.js

Link to the deployed external adapter with the code above:

https://europe-west6-shamba-vpc-host-nonprod.cloudfunctions.net/geoEA-mean

Curl Command I am sending:

curl -X POST -H "content-type:application/json" "https://europe-west6-shamba-vpc-host-nonprod.cloudfunctions.net/geoEA-mean" --data '{ "id": 0, "data": {"dataset_code":"COPERNICUS/S2_SR", "selected_band":"NDVI", "image_scale":250.0, "start_date":"2021-09-01", "end_date":"2021-09-10", "geometry":{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[19.51171875,4.214943141390651],[18.28125,-4.740675384778361],[26.894531249999996,-4.565473550710278],[27.24609375,1.2303741774326145],[19.51171875,4.214943141390651]]]}}]}} }'

Error message I am getting from sending the above curl command:

"name":"AdapterError","message":"Request failed with status code 422"
1
  • N.B: the deployed external adapter link is no longer working as the cloud function has been deleted as of this comment.
    – kenGIS
    Dec 8, 2021 at 22:31

2 Answers 2

0

From the API docs you provided, if the error code is 422 the response looks like this:

{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}

Run the same command, but save the output in a text file (curl ... >> output.txt) and then read the actual error

curl -X POST -H "content-type:application/json" "https://europe-west6-shamba-vpc-host-nonprod.cloudfunctions.net/geoEA-mean" --data '{ "id": 0, "data": {"dataset_code":"COPERNICUS/S2_SR", "selected_band":"NDVI", "image_scale":250.0, "start_date":"2021-09-01", "end_date":"2021-09-10", "geometry":{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[19.51171875,4.214943141390651],[18.28125,-4.740675384778361],[26.894531249999996,-4.565473550710278],[27.24609375,1.2303741774326145],[19.51171875,4.214943141390651]]]}}]}} }' >> output.txt
0

Found the issue. The request was timing out too quickly. Added a timeout parameter to the adapters index.js code as below. Seems to have resolved the problem.

const config = { method: 'post', url, data, timeout: 3600000 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.