I am trying to write a script in R to download data from a JSON-RPC API.
Unfortunately, this API is for a private company service and I can't disclose its name or URL. The error should be reproducible with almost any JSON-RPC API though.
The API's manual instructs me to test the connection with this request:
{
"params": {},
"version": "1.1",
"method": "getConnectionTest"
}
I'm trying with this code:
library(httr)
apiURL <- "http://private.url/found/in/the/manual/JSONRPC.cgi"
apiConnectionTest <- list(params = "", version = "1.1", method = "getConnectionTest")
apiGETConnectionTest <- GET(url = apiURL, body = apiConnectionTest, encode = "json")
content(apiGETConnectionTest)
Or with this code:
library(httr)
apiURL <- "http://private.url/found/in/the/manual/JSONRPC.cgi"
apiConnectionTest <- list(params = "{}", version = "1.1", method = "getConnectionTest")
apiGETConnectionTest <- GET(url = apiURL, body = apiConnectionTest, encode = "json")
content(apiGETConnectionTest)
Or with this code:
library(httr)
library(rjson)
apiURL <- "http://private.url/found/in/the/manual/JSONRPC.cgi"
apiConnectionTest <- toJSON(list("params" = "{}", "version" = "1.1", "method" = "getConnectionTest"))
apiGETConnectionTest <- GET(url = apiURL, body = apiConnectionTest, encode = "json")
content(apiGETConnectionTest)
No matter what I do, I invariably get this response:
$version
[1] "1.1"
$error
$error$name
[1] "JSONRPCError"
$error$message
[1] "No such a method : ''."
$error$code
[1] 302
From the looks of it, but I may be wrong, it looks like the method is formatted wrong and is sent empty. I'm pretty sure the error is mine.
What am I missing?