Calling UCI get or set commands through jsonrpc


When I call uci get or set by " ubus call uci get/set "
its ok

but I can not find any way to call them through uhttpd /ubus path by jsonrpc,

for example:
ubus call uci get '{ "config": "dhcp", "type": "host" }'

it must be like this:
curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "SID", "uci", "get", '{ "config": "dhcp", "type": "host" }' ] }'

curl: (6) Couldn't resolve host 'config'
curl: (6) Couldn't resolve host 'dhcp,'
curl: (6) Couldn't resolve host 'type'
curl: (6) Couldn't resolve host 'host'
curl: (3) [globbing] unmatched close brace/bracket in column 1
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}

Can you please provide some examples for " uci get " or " uci set " by jsonrpc?
there are a lot of questions in the forum about that, but nobody answered :frowning:

It would be great if you could gather your questions in a single thread and not start a new topic for every procedure you want to implement.

You did the same mistake as in your ubus logout call. You need to pass the fourth element in "params": [...] as JSON object not as a string containing JSON.

1 Like

sorry jow, can you plz merge topics ?

do you solved your problem ? how ?

what do you mean? assuming that I am NOT programmer
just for my knowledge
any jsonrpc sample for uci 'GET' or 'SET' please
I am getting "Parse Error" like topic owner

His request is very look like the example : { "name":"John", "age":30, "car":null }

what is the exact mistake in this request ?
he is sending [ "SID", "uci", "get", '{ "config": "dhcp", "type": "host" }' ]

can you correct @Shoot426 jsonrpc request to my better understanding ?

thank you for being helpful

No :frowning:

I've checked the main command on ubus again, and it's working:

ubus call uci get '{"config": "dhcp", "type": "host"}'
        "values": {
                "cfg07fe63": {
                        ".anonymous": true,
                        ".type": "host",
                        ".name": "cfg07fe63",
                        ".index": 4,
                        "name": "mydesktop0",
                        "mac": "bc:b5:c5:75:37:9a",
                        "ip": ""

and now using jsonrpc and sending json object :

curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "000000000000000000000000000000000", "uci", "get", { "config": "dhcp", "type": "host" } ] }

ubus monitoring, says incorrect uci get parameters !

-> 4a737e3b #cdb38f44         status: {"status":0,"objid":-843870396}
<- 33f685cc #00000000         lookup: {"objpath":"uci"}
-> 33f685cc #00000000           data: {"objpath":"uci","objid":-1660065295,"objtype":1960058797,"signature":{"configs":{},"get":{"config":3,"section":3,"option":3,"type":3,"match":2,"ubus_rpc_session":3},"state":{"config":3,"section":3,"option":3,"type":3,"match":2,"ubus_rpc_session":3},"add":{"config":3,"type":3,"name":3,"values":2,"ubus_rpc_session":3},"set":{"config":3,"section":3,"type":3,"match":2,"values":2,"ubus_rpc_session":3},"delete":{"config":3,"section":3,"type":3,"match":2,"option":3,"options":1,"ubus_rpc_session":3},"rename":{"config":3,"section":3,"option":3,"name":3,"ubus_rpc_session":3},"order":{"config":3,"sections":1,"ubus_rpc_session":3},"changes":{"config":3,"ubus_rpc_session":3},"revert":{"config":3,"ubus_rpc_session":3},"commit":{"config":3,"ubus_rpc_session":3},"apply":{"rollback":7,"timeout":5,"ubus_rpc_session":3},"confirm":{"ubus_rpc_session":3},"rollback":{"ubus_rpc_session":3},"reload_config":{}}}

jsonrpc for noobs like me is so confusing :frowning:

First I need to get static DHCP leases and use SET to change some values through /ubus call

any correct example will be great and useful.

Code 6 is UBUS_STATUS_PERMISSION_DENIED. The null session is not allowed to read uci files.

1 Like

that was not null, I just removed my SID,

Is it possible to restart services by ubus call ?
for example if we delete dhcp static hosts, then we have to restart "dnsmasq" and "odhcpd" services

any way to restart services by ubus ?

If you invoke uci apply through ubus, then procd enabled services (such as dnsmasq or odhcpd) should automatically reload the configuration.

1 Like