I’m Facing a little problem with with RPC call via postman - The error I’m getting -
{
"error": "D:\\UnityProjects\\Server\\data\\modules\\match_handlers\\server_time.lua:16: bad argument #1 to json_decode (expects JSON string)\nstack traceback:\n\t[G]: in function 'json_decode'\n\tD:\\UnityProjects\\Server\\data\\modules\\match_handlers\\server_time.lua:16: in main chunk\n\t[G]: ?",
"message": "D:\\UnityProjects\\Server\\data\\modules\\match_handlers\\server_time.lua:16: bad argument #1 to json_decode (expects JSON string)\nstack traceback:\n\t[G]: in function 'json_decode'\n\tD:\\UnityProjects\\Server\\data\\modules\\match_handlers\\server_time.lua:16: in main chunk\n\t[G]: ?",
"code": 13
}
Here’s my example RPC -
--- RPC call to get server time
function s_t.get_server_time(context, payload)
log.log_debug("[get_server_time] : context = " .. nk.json_encode(context))
log.log_debug("[get_server_time] : type of payload = " .. type(payload))
log.log_debug("[get_server_time] : payload = " .. payload)
local json = nk.json_decode(payload)
local result = {
c_time = json.s_time,
s_time = nk.time(),
reset = json.reset
}
--log.log_norm("[server_time/get_server_time] : ----> Client time " .. result.c_time, " & sent server_time : " .. result.s_time)
return nk.json_encode(result)
end
Server logs -
[get_server_time] : context = {"client_ip":"127.0.0.1","env":{},"execution_mode":"rpc","query_params":{}}
[get_server_time] : type of payload = string
[get_server_time] : payload =
{"level":"error","ts":"2019-07-24T13:17:44.620+0530","msg":"Runtime RPC function caused an error","id":"get_server_time","error":"D:\\UnityProjects\\Server\\data\\modules\\match_handlers\\server_time.lua:16: bad argument #1 to json_decode (expects JSON string)\nstack traceback:\n\t[G]: in function 'json_decode'\n\tD:\\UnityProjects\\Server\\data\\modules\\match_handlers\\server_time.lua:16: in main chunk\n\t[G]: ?","stacktrace":"github.com/heroic ...........................................
I’m passing this data as raw "{\"s_time\": 123456}"
with content type application/json
.
I’ve tried several variations for sending raw data too like this one - {"s_time": 123456}
but same error.
Want to have an example on how to properly send payload to custom RPC via Postman.