Not sure what is going on. When I perform the following code… it runs fine… but it is producing an error. If I paste the following into my browser address bar and hit it, I get one URL. If I put the same url through the KRL http:get, I get a completely different URL.
“http://tinyurl.com/api-create.php?url=http://insideaf.blogspot.com”
on my own in the browser I get: http://tinyurl.com/6j7qucx
when run through http:get I get: http://tinyurl.com/4fdtnoo
The difference is that the second one, the one run through the KRL http:get hits the requested site, but it appends a “/&” to the end of the request. It does this no matter what site I am on. If I am on http://www.google.com, it returns a tinyurl that results in http://www.google.com/& with gives me an error. All sites that I pass to the http:get method get returned with an & at the end. Here is my code, so that you can see that I am not accidentally adding it myself.
myLocation = event:param(“location”);
url2tiny = “http://tinyurl.com/api-create.php?url=”+myLocation;
tinyresponse = http:get(url2tiny);
tinyurl = tinyurl.pick(“$.content”);
If I console.log the url2tiny, it looks exactly like it should. It appears that when I pass url2tiny to http:get, it is automatically adding the & to the end of it before it requests it from the tinyurl api.
Any ideas for workarounds to this issue? It appears to be a bug in the http:get method. If I am wrong (and I hope I am), please point me in the right direction.
In both cases, your format is just slightly off. http:get can be used as an expression in the pre block, but the syntax is different from the way that you use it in the action block.
There are actually a number of different ways that you could make this request. The traditional way is through a datasource
DATASOURCE
The other way is how you were trying and it is through http:get as an expression in the pre block. Called as a function, http:get has 2 required parameters and two optional parameters:
Your first attempt did not include the params.
tinyresponse = http:get(url2tiny)
The second attempt places the params in the wrong argument position.
http:get(“tinyurl.com/api-create.php”;,{“url”:myurl})
http:get (pre block)
The third method is using http:get as an action and auto-raising an event
http:get (action)
Here is an example of these rules executing against this very page
