Hello,
the rpc interface is not matching parameters by name, but by possition. You can add them with name, but must be at the right/expected possition.
In your last example, body field is out of parameters structure. And as it was pointed out before, you need an id in the root jsonrpc structure.
See some examples at:
- https://www.kamailio.org/docs/modules/stable/modules/jsonrpcs.html#idm1028042236
Cheers,
Daniel
Hello Serge,
Thank you for clarifying this for me. But there is different issue when I change format. It appears that Kamailio indeed expects body under parameters https://www.kamailio.org/docs/modules/5.2.x/modules/pua_rpc.html#pua_rpc.r.pua.publish.
I run:Result:# curl -H "Content-Type: application/json" -X POST -d '{"jsonrpc": "2.0", "method": "pua.publish", "params": {"presentity_uri": "sip:jh@test.tutpro.com", "expires": "600", "event package": "message-summary", "content type": "application/simple-message-summary", "id": "4ce8c647a7b947c@172.16.30.151", "ETag": ".", "outbound proxy": "sip:127.0.0.1:5060;transport=udp", "extra_headers": "P-Flags: 0"}, "body": 1}' http://172.16.30.151:5060/JSON_RPC
{"jsonrpc": "2.0","error": {"code": 400,"message": "Body is missing"}}
Debug:Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: <script>: == TRACE. xhttp:requestJan 22 18:41:36 test kamailio: 14(27146) DEBUG: <script>: == TRACE. xhttp:request. /JSON_RPCJan 22 18:41:36 test kamailio: 14(27146) DEBUG: <core> [core/parser/msg_parser.c:185]: get_hdr_field(): content_length=355Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: <core> [core/parser/msg_parser.c:89]: get_hdr_field(): found end of headerJan 22 18:41:36 test kamailio: 14(27146) DEBUG: pua_rpc [pua_rpc.c:155]: pua_rpc_publish_mode(): rpc publishing ...Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: pua_rpc [pua_rpc.c:178]: pua_rpc_publish_mode(): presentity uri 'sip:jh@test.tutpro.com'Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: pua_rpc [pua_rpc.c:193]: pua_rpc_publish_mode(): expires '600'Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: pua_rpc [pua_rpc.c:195]: pua_rpc_publish_mode(): event 'message-summary'Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: pua_rpc [pua_rpc.c:197]: pua_rpc_publish_mode(): content type 'application/simple-message-summary'Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: pua_rpc [pua_rpc.c:199]: pua_rpc_publish_mode(): id '4ce8c647a7b947c@172.16.30.151'Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: pua_rpc [pua_rpc.c:201]: pua_rpc_publish_mode(): ETag '.'Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: pua_rpc [pua_rpc.c:203]: pua_rpc_publish_mode(): outbound_proxy 'sip:127.0.0.1:5060;transport=udp'Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: pua_rpc [pua_rpc.c:205]: pua_rpc_publish_mode(): extra headers 'P-Flags: 0'Jan 22 18:41:36 test kamailio: 14(27146) ERROR: pua_rpc [pua_rpc.c:211]: pua_rpc_publish_mode(): body is missing, but content type is not .Jan 22 18:41:36 test kamailio: 14(27146) DEBUG: jsonrpcs [jsonrpcs_mod.c:423]: jsonrpc_send(): sending response with body: 0x7ffc3b0e2290 - 400 Body is missingJan 22 18:41:36 test kamailio: 14(27146) DEBUG: xhttp [xhttp_mod.c:429]: xhttp_send_reply(): response with content-type: application/jsonJan 22 18:41:36 test kamailio: 14(27146) DEBUG: xhttp [xhttp_mod.c:439]: xhttp_send_reply(): response with body: {Jan 22 18:41:36 test kamailio: "jsonrpc":#011"2.0",Jan 22 18:41:36 test kamailio: "error":#011{Jan 22 18:41:36 test kamailio: "code":#011400,Jan 22 18:41:36 test kamailio: "message":#011"Body is missing"Jan 22 18:41:36 test kamailio: }Jan 22 18:41:36 test kamailio: }
вт, 22 січ. 2019 о 17:05 Serge S. Yuriev <me@nevian.org> пише:
Hi
id is not inside params but must to be at top-level.
You have to read JSONRPC specs %)
https://www.jsonrpc.org/specification
On 22/01/2019 13:47, Володимир Іванець wrote:
> Hello Henning,
>
> Thank you for your message. I tried setting *id* too but got same result.
>
> /# curl -H "Content-Type: application/json" -X POST -d '{"jsonrpc":
> "2.0", "method": "pua.publish", "params": {"presentity_uri":
> "sip:h@test.tutpro.com <mailto:sip%3Ah@test.tutpro.com>", "expires":
> "600", "event package": "message-summary", "content type":
> "application/simple-message-summary", "id":
> "NmU0MjI0NWM4ZjI3MWI3NTNlMTJhOWNlZWJlMWE0Yzg.", "ETag": ".",
> "outbound proxy": "sip:127.0.0.1:5060;transport=udp",
> "extra_headers": "P-Flags: 0", "body": "."}}'
> http://172.16.30.151:5060/JSON_RPC/
> /{/
> / "jsonrpc": "2.0",/
> / "error": {/
> / "code": 500,/
> / "message": "Internal error: failed to create
> context"/
> / }/
> /}/
>
>
>
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: <script>: == TRACE.
> xhttp:request/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: <script>: == TRACE.
> xhttp:request. /JSON_RPC/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: <core>
> [core/parser/msg_parser.c:185]: get_hdr_field(): content_length=372/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: <core>
> [core/parser/msg_parser.c:89]: get_hdr_field(): found end of header/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:155]: pua_rpc_publish_mode(): rpc publishing .../
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:178]: pua_rpc_publish_mode(): presentity uri
> 'sip:jh@test.tutpro.com <mailto:sip%3Ajh@test.tutpro.com>'/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:193]: pua_rpc_publish_mode(): expires '600'/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:195]: pua_rpc_publish_mode(): event 'message-summary'/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:197]: pua_rpc_publish_mode(): content type
> 'application/simple-message-summary'/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:199]: pua_rpc_publish_mode(): id
> 'NmU0MjI0NWM4ZjI3MWI3NTNlMTJhOWNlZWJlMWE0Yzg.'/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:201]: pua_rpc_publish_mode(): ETag '.'/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:203]: pua_rpc_publish_mode(): outbound_proxy
> 'sip:127.0.0.1:5060;transport=udp'/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:205]: pua_rpc_publish_mode(): extra headers 'P-Flags: 0'/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: pua_rpc
> [pua_rpc.c:207]: pua_rpc_publish_mode(): body '.'/
> /Jan 22 12:40:54 test kamailio: 16(26145) ERROR: jsonrpcs
> [jsonrpcs_mod.c:1010]: jsonrpc_delayed_ctx_new(): id attribute is
> missing/
> /Jan 22 12:40:54 test kamailio: 16(26145) ERROR: pua_rpc
> [pua_rpc.c:256]: pua_rpc_publish_mode(): internal error: failed to
> create context/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: jsonrpcs
> [jsonrpcs_mod.c:423]: jsonrpc_send(): sending response with body:
> 0x7ffd167c0ef0 - 500 Internal error: failed to create context/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: xhttp
> [xhttp_mod.c:429]: xhttp_send_reply(): response with content-type:
> application/json/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: xhttp
> [xhttp_mod.c:439]: xhttp_send_reply(): response with body: {/
> /Jan 22 12:40:54 test kamailio: "jsonrpc":#011"2.0",/
> /Jan 22 12:40:54 test kamailio: "error":#011{/
> /Jan 22 12:40:54 test kamailio: "code":#011500,/
> /Jan 22 12:40:54 test kamailio: "message":#011"Internal error:
> failed to create context"/
> /Jan 22 12:40:54 test kamailio: }/
> /Jan 22 12:40:54 test kamailio: }/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: xhttp
> [xhttp_mod.c:441]: xhttp_send_reply(): sending out response: 500
> Internal error: failed to create context/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: <core>
> [core/msg_translator.c:162]: check_via_address(): (172.16.30.151,
> 172.16.30.151, 0)/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: <core>
> [core/tcp_main.c:2226]: tcpconn_send_put(): send from reader (26145
> (16)), reusing fd/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: <core>
> [core/tcp_main.c:2460]: tcpconn_do_send(): sending.../
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: <core>
> [core/tcp_main.c:2494]: tcpconn_do_send(): after real write: c=
> 0x7f8b7f314f68 n=297 fd=8/
> /Jan 22 12:40:54 test kamailio: 16(26145) DEBUG: <core>
> [core/tcp_main.c:2495]: tcpconn_do_send(): buf=/
> /Jan 22 12:40:54 test kamailio: HTTP/1.1 500 Internal error: failed
> to create context/
> /Jan 22 12:40:54 test kamailio: Sia: SIP/2.0/TCP 172.16.30.151:44226
> <http://172.16.30.151:44226>/
> /Jan 22 12:40:54 test kamailio: Content-Type: application/json/
> /Jan 22 12:40:54 test kamailio: Server: kamailio (5.2.1 (x86_64/linux))/
> /Jan 22 12:40:54 test kamailio: Content-Length: 108/
> /Jan 22 12:40:54 test kamailio: {/
> /Jan 22 12:40:54 test kamailio: "jsonrpc":#011"2.0",/
> /Jan 22 12:40:54 test kamailio: "error":#011{/
> /Jan 22 12:40:54 test kamailio: "code":#011500,/
> /Jan 22 12:40:54 test kamailio: "message":#011"Internal error:
> failed to create context"/
> /Jan 22 12:40:54 test kamailio: }/
> /Jan 22 12:40:54 test kamailio: }/
>
>
> пн, 21 січ. 2019 о 23:16 Henning Westerholt <hw@kamailio.org
> <mailto:hw@kamailio.org>> пише:
>
> Am Montag, 21. Januar 2019, 19:10:11 CET schrieb Володимир Іванець:
> > Are you able to generate PUBLISH message with jsonrpcs? I can
> only do it
> > with xmlrpc. Kamailio version is 5.2.1.
> >
> > When I use jsonrpc:
>
> Hello,
>
> not looked that deep into it, but have you tried to set an id (as
> reported
> from this error message?
>
> Jan 21 19:37:58 test kamailio: 13(25583) ERROR: jsonrpcs
> [jsonrpcs_mod.c:
> 1010]: jsonrpc_delayed_ctx_new(): id attribute is missing
>
> Best regards,
>
> Henning
>
>
> > *# curl -H "Content-Type: application/json" -X POST -d
> '{"jsonrpc": "2.0",
> > "method": "pua.publish", "params": {"presentity_uri":
> > "sip:jh@test.tutpro.com <mailto:sip%3Ajh@test.tutpro.com>
> <sip%3Ajh@test.tutpro.com <mailto:sip%253Ajh@test.tutpro.com>>",
> "expires": "600",
> > "event package": "message-summary", "content type":
> > "application/simple-message-summary", "id": ".", "ETag": ".",
> "outbound
> > proxy": "sip:127.0.0.1:5060;transport=udp", "extra_headers":
> "P-Flags: 0",
> > "body": "."}}' http://172.16.30.151:5060/JSON_RPC
> > <http://172.16.30.151:5060/JSON_RPC>*
> >
> > I get:
> >
> > *{*
> > * "jsonrpc": "2.0",*
> > * "error": {*
> > * "code": 500,*
> > * "message": "Internal error: failed to
> create context"*
> > * }*
> >
> >
> > Debug output:
> >
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: <script>: == TRACE.
> > xhttp:request*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: <script>: == TRACE.
> > xhttp:request. /JSON_RPC*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: <core>
> > [core/parser/msg_parser.c:185]: get_hdr_field(): content_length=329*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: <core>
> > [core/parser/msg_parser.c:89]: get_hdr_field(): found end of header*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:155]:
> > pua_rpc_publish_mode(): rpc publishing ...*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:178]:
> > pua_rpc_publish_mode(): presentity uri 'sip:jh@test.tutpro.com
> <mailto:sip%3Ajh@test.tutpro.com>
> > <sip%3Ajh@test.tutpro.com <mailto:sip%253Ajh@test.tutpro.com>>'*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:193]:
> > pua_rpc_publish_mode(): expires '600'*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:195]:
> > pua_rpc_publish_mode(): event 'message-summary'*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:197]:
> > pua_rpc_publish_mode(): content type
> 'application/simple-message-summary'*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:199]:
> > pua_rpc_publish_mode(): id '.'*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:201]:
> > pua_rpc_publish_mode(): ETag '.'*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:203]:
> > pua_rpc_publish_mode(): outbound_proxy
> 'sip:127.0.0.1:5060;transport=udp'*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:205]:
> > pua_rpc_publish_mode(): extra headers 'P-Flags: 0'*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: pua_rpc
> [pua_rpc.c:207]:
> > pua_rpc_publish_mode(): body '.'*
> > *Jan 21 19:37:58 test kamailio: 13(25583) ERROR: jsonrpcs
> > [jsonrpcs_mod.c:1010]: jsonrpc_delayed_ctx_new(): id attribute is
> missing*
> > *Jan 21 19:37:58 test kamailio: 13(25583) ERROR: pua_rpc
> [pua_rpc.c:256]:
> > pua_rpc_publish_mode(): internal error: failed to create context*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: jsonrpcs
> > [jsonrpcs_mod.c:423]: jsonrpc_send(): sending response with body:
> > 0x7fffc28e6e80 - 500 Internal error: failed to create context*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: xhttp
> [xhttp_mod.c:429]:
> > xhttp_send_reply(): response with content-type: application/json*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: xhttp
> [xhttp_mod.c:439]:
> > xhttp_send_reply(): response with body: {*
> > *Jan 21 19:37:58 test kamailio: "jsonrpc":#011"2.0",*
> > *Jan 21 19:37:58 test kamailio: "error":#011{*
> > *Jan 21 19:37:58 test kamailio: "code":#011500,*
> > *Jan 21 19:37:58 test kamailio: "message":#011"Internal error:
> failed to
> > create context"*
> > *Jan 21 19:37:58 test kamailio: }*
> > *Jan 21 19:37:58 test kamailio: }*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: xhttp
> [xhttp_mod.c:441]:
> > xhttp_send_reply(): sending out response: 500 Internal error:
> failed to
> > create context*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: <core>
> > [core/msg_translator.c:162]: check_via_address(): (172.16.30.151,
> > 172.16.30.151, 0)*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: <core>
> > [core/tcp_main.c:2226]: tcpconn_send_put(): send from reader
> (25583 (13)),
> > reusing fd*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: <core>
> > [core/tcp_main.c:2460]: tcpconn_do_send(): sending...*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: <core>
> > [core/tcp_main.c:2494]: tcpconn_do_send(): after real write: c=
> > 0x7f7af5a39888 n=297 fd=8*
> > *Jan 21 19:37:58 test kamailio: 13(25583) DEBUG: <core>
> > [core/tcp_main.c:2495]: tcpconn_do_send(): buf=*
> > *Jan 21 19:37:58 test kamailio: HTTP/1.1 500 Internal error:
> failed to
> > create context*
> > *Jan 21 19:37:58 test kamailio: Sia: SIP/2.0/TCP
> 172.16.30.151:44122 <http://172.16.30.151:44122>
> > <http://172.16.30.151:44122>*
> > *Jan 21 19:37:58 test kamailio: Content-Type: application/json*
> > *Jan 21 19:37:58 test kamailio: Server: kamailio (5.2.1
> (x86_64/linux))*
> > *Jan 21 19:37:58 test kamailio: Content-Length: 108*
> > *Jan 21 19:37:58 test kamailio: {*
> > *Jan 21 19:37:58 test kamailio: "jsonrpc":#011"2.0",*
> > *Jan 21 19:37:58 test kamailio: "error":#011{*
> > *Jan 21 19:37:58 test kamailio: "code":#011500,*
> > *Jan 21 19:37:58 test kamailio: "message":#011"Internal error:
> failed to
> > create context"*
> > *Jan 21 19:37:58 test kamailio: }*
> > *Jan 21 19:37:58 test kamailio: }*
> >
> > Thanks!
> >
> > пн, 17 вер. 2018 о 09:18 Juha Heinanen <jh@tutpro.com
> <mailto:jh@tutpro.com>> пише:
> > > willy writes:
> > > > Have anyone tried to use pua.publish to send MWI
> notification? Can it
> > > > work at all?
> > > >
> > > > I'm sending request through jsonrpc server, but it is not
> dispatched by
> > > > handle_publish.
> > >
> > > It works fine here. Last week I noticed an issue with
> pua.publish over
> > > jsonrpc and it was fixed. Even before the fix, pua.publish
> worked, but
> > > an error message was issued.
>
>
>
>
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users@lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>
--
Serge S. Yuriev
Senior VoIP engineer
_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
_______________________________________________ Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
-- Daniel-Constantin Mierla -- www.asipto.com www.twitter.com/miconda -- www.linkedin.com/in/miconda Kamailio World Conference - May 6-8, 2019 -- www.kamailioworld.com Kamailio Advanced Training - Mar 4-6, 2019 in Berlin; Mar 25-27, 2019, in Washington, DC, USA -- www.asipto.com