vtnerd/monero-lws

Rest API usage examples

Closed this issue · 3 comments

Could you please give some basic examples of how to communicate with this service using REST API? All CURL's just return an empty response message, ie:

ubuntu@ip-10-20-0-169:~$ curl --location --request POST 'http://127.0.0.1:8443/import_request?address=47smcRfD5u2BRa3BFoweA56qQgVZnktoJJXHctdXGWW3RH4pRavkYXKWC3QR5GeJ3fY8RkVP2Ai9eWV6yD5UuQugMum5DE3&view_key=4aa48a80104523e57dd20eb49a00cb7f8de2fb317013d97bd7d040a89fb7ae0d'
curl: (52) Empty reply from server

I also get strange failure messages trying to set the service to accept all pending requests:

ubuntu@ip-10-20-0-169:~$ monero-lws-admin accept_requests create $(monero-lws-admin list_requests | jq -j '.create? | .[]? | .address?+" "')
accept_requests requires 2 or more arguments

Did you bind a http server to 8443 like this? ./monero-lws-daemon --rest-server "http://127.0.0.1:8443"

Here is an example:

curl -w "\n" -X POST http://127.0.0.1:8443/get_address_info -d '{"address": "4KKjaofUmB8a1fsdhs5Qy3WGCd2tYgfsdkGtvEhTqhgpcNuR56dLJVfoiztWoz86wY3PstiuBYruxKqwjsfdhbkQYDr3pmGYHGBVvn7", "view_key": "6fb7caa33sdbd97328270826c3e98603aaaf043075eb82748e6aabbd25171830f"}'  -H 'Content-Type: application/json'
ndorf commented

The parameters address and view_key must be provided in JSON format in the POST body, not as query parameters.

E.g., curl --location --header 'Content-type: application/json' --data '{"address":"47smcRfD5u2BRa3BFoweA56qQgVZnktoJJXHctdXGWW3RH4pRavkYXKWC3QR5GeJ3fY8RkVP2Ai9eWV6yD5UuQugMum5DE3","view_key":"4aa48a80104523e57dd20eb49a00cb7f8de2fb317013d97bd7d040a89fb7ae0d"}' 'http://127.0.0.1:8443/import_request'

(--request POST is implied when --data is present, so you can omit it)

See here for complete documentation of this API.

Thank you @selsta and @ndorf, I didn't realise I needed to explicitly activate rest in my service file. Both your examples are now working for me.

In case anyone else is reading this with my problem here is a working service file config for this application:

[Unit]
Description=Monero LWS
After=network.target

[Service]
User=ubuntu
Group=ubuntu
ExecStart=/home/ubuntu/monero-lws/build/src/monero-lws-daemon --db-path /home/ubuntu/block_volume/light_wallet_server --rest-server "http://127.0.0.1:8443"
Restart=always

[Install]
WantedBy=multi-user.target