JSONRPC request with curl

user3767873 picture user3767873 · Jun 23, 2014 · Viewed 13k times · Source

I have a 32602 error for all requests using dictionary as params, whereas these work with a simple params.

For example:

curl -d '{"id":"json","method":"add","params":[1,2] }' -o – ‘http address for json rpc’

works, but :

curl -d '{"id":"json","method":"add","params":[{"a":2,"b":3}] }' -o – ‘http address for json rpc’’

returns a 32602 error (Invalid parameters!!!)

I need to put at params a name and a type and I need a dictionary for this, but I receive a 32602 error. What is wrong ?

Answer

Cameron Little picture Cameron Little · Apr 26, 2020

The specific error you're receiving ("Invalid parameters") does indicate your parameter type may be wrong for the specific method you're invoking, but for anyone looking for general guidance for making JSON-RPC calls with curl, that may not be the issue.

For JSON-RPC 2.0 the spec requires passing a string specifying the protocol version, "jsonrpc": "2.0", which is missing in the question's example.

Here's an example of a compliant, working call (tested with a jayson server):

curl -X POST \
     -H 'Content-Type: application/json' \
     -d '{"jsonrpc":"2.0","id":"id","method":"add","params":[1, 2]}' \
     http://localhost:3000