2

I`m following a tutorial on making external adapters for chainlink node https://www.youtube.com/watch?v=65NhO5xxSZc&list=LL&index=9&t=150s and having some trouble with the curl -x POST command. In the tutorial he is using a MacOS and the curl command is:

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

When running this command in CMD i get : enter image description here

I now somewhat understand that in Windows for the right syntax I have to wrap the JSON in double-quotes and add an escape character, so I did:

curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data "{ \"id\": 0, \"data\": {\"from\": \"ETH\", \"to\": \"USD\"} } "

But still, Im getting an error...what would the right curl syntax look like in this example ? And i`m using VCS and runnning the two terminals in CMD should I be using PowerShell or Git Bash terminals instead ?

Im running on Win 10 X64, 20H2 10.0.19042.1110

Thx

heyooo12
  • 139
  • 3
  • 16
  • 1
    Replicate: Look at this: https://stackoverflow.com/questions/11834238/curl-post-command-line-on-windows-restful-service – Kimon M Jul 30 '21 at 08:39
  • Does this answer your question? [cURL POST command line on WINDOWS RESTful service](https://stackoverflow.com/questions/11834238/curl-post-command-line-on-windows-restful-service) – Kimon M Jul 30 '21 at 08:43
  • Can you add the code instead of images? It makes it hard to search for – Patrick Collins Aug 04 '21 at 14:44

2 Answers2

1

It was not the curl command that was the problem, but the \node_modules@chainlink\external-adapter\src\validator.js. I changed the parameters from default to constructor(callback, input, customParams) now I can curl with curl -X POST -H "Content-Type:application/json" "http://localhost:8080" --data "{ \"id\": 0, \"data\": { \"from\" : \"ETH\" , \"to\" : \"USD\" } }"

and get the ETH price feed returned.

heyooo12
  • 139
  • 3
  • 16
  • yes you are right, turns out that in windows cmd single quotes do not work, so this would give an error: curl 'http://localhost:6001/' while this would work curl "http://localhost:6001/" – shabby May 15 '23 at 08:42
-1

Just a bit more explanation, if it helps someone

This works perfectly on linux shell (git bash terminal):

curl -X POST -H "content-type:application/json" "http://localhost:6001/" --data '{ "id": 0, "data": { "coin": "ETH", "market": "USD" } }'

gives this response (output from git bash):

{"timestamp":"2023-05-15T07:39:26.203+00:00","status":404,"error":"Not Found","message":"","path":"/"}

Note: request doesn't have the error

But the same when tried on windows' new command prompt gives this error:

curl -X POST -H "content-type:application/json" "http://localhost:8080/" --data '{ "id": 0, "data": { "coin": "ETH", "market": "USD" } }'
curl: (7) Failed to connect to localhost port 8080 after 2245 ms: Couldn't connect to server
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched brace in URL position 1:

so to fix it you need to do exactly whats pointed out in the answer by OP (i.e. change the single quote to double quotes and escape the double quotes inside):

WORKS perfectly:

curl -X POST -H "content-type:application/json" "http://localhost:6001/" --data "{ \"id\": 0, \"data\": { \"coin\": \"ETH\", \"market\": \"USD\" } }"
shabby
  • 3,002
  • 3
  • 39
  • 59