Skip to main content
1-Visitor
September 24, 2018
Solved

Trouble with passing json in the url in Rest calls

  • September 24, 2018
  • 2 replies
  • 2056 views

I currently have a url: http://172.20.100.3/cgi-bin/json.cgi?json={"method": "broadcaston", "params": [1], "id": 10}

 

This is for lighting control, and the json controls what happens with the lights and returns a json when you go to the web page. I am currently using the GetJson snippet and passing in the json.

 

var Mycontent = {
"method" : "broadcastoff",
"params" : "[1]",
"id" : "30"
}

var params = {
url: "http://172.20.100.3/cgi-bin/json.cgi?json=", 
content: Mycontent, 
};


var result = Resources["ContentLoaderFunctions"].GetJSON(params);

All that is being returned is - {"headers":""}

 

Any help with where I'm going wrong would be greatly appreciated. 

 

 

This topic has been closed for replies.
Best answer by JonathonFowler

The solution is to encapsulate the whole link as a string and use %7b instead of {.

And use %7d instead of }.

 

 

2 replies

22-Sapphire I
September 24, 2018

What all have you tried so far with the parameters?

Can you try to create the json but 'encapsulated' as a string does that make any difference?

also for the return, instead of doing getjson, try gettext first and see if anything at all is returned.

1-Visitor
September 25, 2018

All I am passing into the parameters is the url, and sometimes the content depending on what I'm trying. 

 

When I try to encapsulate the JSON I got the error -

 

"Error executing service LightTest. Message :: Illegal character in opaque part at index 40: http:172.20.100.3/cgi-bin/json.cgi?json={"method":"broadcastoff","params":"[1]","id":"30"} - See Script Error Log for more details."

 

That is with both getJSON and getText.

JonathonFowler1-VisitorAuthorAnswer
1-Visitor
September 25, 2018

The solution is to encapsulate the whole link as a string and use %7b instead of {.

And use %7d instead of }.