Closed VitruxPT closed 7 years ago
I plan to write a complete tutorial(which will be found here) with explanations and examples.
In the mean time, here is a post request:
alias post {
;; Compile the post data
;; for this example we'll be using form-encoded data
var %data = key=value&key2=value2&key3=value3
;; open the json handle, but have it wait(-w)
;; for /JSONHttpFetch to be called
JSONOpen -duw example example.com
;; set the request method to post
JSONHttpMethod example POST
;; Include the post data, with the fetch command
;; Since the Content-Type, and Content-Length
;; headers were NOT specified, the script
;; will use default values
JSONHttpFetch example %data
;; from here you'd access the retrieved data as usual
}
And to delete:
alias del {
;; open the json handle, but have it wait(-w)
;; for /JSONHttpFetch to be called
JSONOpen -duw example example.com/resource/to/delete
;; Set the request method to delete
JSONHttpMethod example DELETE
;; Make the request
JSONHttpFetch example
;; from here you'd access the retrieved data as usual
}
Well, before writing the tutorial which I can imagine will take some time, can you tell me what I'm doing wrong in this simple GET script? @SReject
alias now_playing {
var %authkey = ************************************
var %user = *********
var %u = http://ws.audioscrobbler.com/2.0/?method=user.getRecentTracks&api_key= $+ %authkey $+ &user= $+ %user $+ &nowplaying=true&limit=1&format=json
var %v = now_playing_ $+ $ticks $+ $ctime
JSONOpen -ud %v %u
echo -s IS: $json(%v,recenttracks,track,0,artist,#text)
JSONClose %v
return
}
Json for reference:
{
"recenttracks":{
"track":[
{
"artist":{
"#text":"Marshmello",
"mbid":""
},
"name":"Alone",
"streamable":"0",
"mbid":"",
"album":{
"#text":"Alone",
"mbid":""
}
}
]
}
}
The json path is correct but I don't seem to be able to get the correct value, instead I'm getting %v
with an integer after: JSON:auth_match_91414622501488210291:9141462421
I was missing the .value
from the $json(%v,recenttracks,track,0,artist,#text)
Hi,
Could you please include an example of part of a script for a request that needs to send data like a POST and one that doesn't like a DELETE? The docs are a bit confusing without any examples. I think examples are the only thing that is missing from this amazing repo :+1:
Thanks in advance