struggle with crafting an API request

+75 votes

hi everyone,

I am having difficulties with crafting my first API-request over postman.

I have set up a chain, I have the explorer and the web-demo running successfully - pretty much default values everywhere:

chain1/multichain.conf:
rpcallowip=192.168.10.0/24
rpcuser=multichainrpc
rpcpassword=XXXX

chain1/params.dat:
default-network-port = 5759
default-rpc-port = 5758
chain-name = chain1

when running a command from the console, everthing works:

bbking@bc-debian:~/.multichain/chain1$ multichain-cli chain1 getinfo
{"method":"getinfo","params":[],"id":"37999825-1712336614","chain_name":"chain1"}

{
    "version" : "2.3.3",
    "nodeversion" : 20303901,
    "edition" : "Community",
    "protocolversion" : 20013,
    "chainname" : "chain1",
    "description" : "MultiChain chain1",
    "protocol" : "multichain",
    "port" : 5759,

now my first question is, do I connect from an external host over port 5759 or 5758?

I wanted to replicate the "getinfo" command from postman:
http://192.168.10.114:5758?method=getinfo&params=[]&id=13054619-1712335590&chain_name=chain1

I have populated the "params" tab with the parameters as you can see.

I also activated "Basic Authorization" with the credentials from multichain.conf

On the "headers" tab, I've set these key-value pairs:
"Content-type" : "application/json"
"Accept" : "application/json"
"Content-length" : the length of the parameter string starting from "?" in the example above.

Now, when I send the request to port 5759, I get a "Could not get response"

when I send the request to port 5758 with "Content-length" activated, it times out.
without "Content-length" activated, I instantly get a "404 Not found"

Can someone help me with what am I doing wrong?

Thanks a lot in advance!

asked Apr 5 by bbking

1 Answer

0 votes

For the node JSON-RPC API, you use the RPC port, i.e. 5758.

It looks like you might be trying to pass the method name and other params as parameters in the URL of a GET request. But they need to be in JSON format in the body of a POST request.

Whenever you use multichain-cli, it shows you what the POST request body contains – like in the example you showed above:

{"method":"getinfo","params":[],"id":"37999825-1712336614","chain_name":"chain1"}
answered Apr 6 by MultiChain
thanks, now I got it working with postman with setting the body parameter as "Raw" and the value is {"method":"getinfo","params":[],"id":"37999825-1712336614","chain_name":"chain1"} as a JSON object.

Tried the same with Node-Red and I was struggling to get the body parameter right.
I tried the JSON object from above as an object but also converted into a string, but I also get 403 forbidden error.
Then I realised the docker container for Node-Red had a different ip range (172.18.0.0/16) than my host computer (192.168.10.0/24) so had to include that range in my multichain.conf and voila! it worked!
Now I create the msg.payload as a JSON object, convert it with the JSON-parser node to JSON-string and send to with the http request to multichain.
Great, thanks for the update!
...