cURL to lua syntax

Hi,

Seems i got myself into a corner with a syntax I haven’t been able to solve yet.

I am mainly struggling with the body part.

Here is the cURL I am trying to convert:

curl -X PUT "https://api.spotify.com/v1/me/player/play" -H "Accept: application/json" -H "Authorization: Bearer ACCESS\_TOKEN" -H "Content-Type: application/json" --data "{\"context\_uri\":\"spotify:album:5ht7ItJgpBH7W6vJ5BqpPr\",\"offset\":{\"position\":5}}"

What I got so far in lua is this:

network.request("https://api.spotify.com/v1/me/player/play","PUT",LISTENER,{body={"context\_uri":"spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",headers={["Authorization"]="Bearer "..ACCESS\_TOKEN,["Content-Type"]="application/json"}}})

You can try your own if you like by going to the spotify web console at https://developer.spotify.com/web-api/console/put-play/#complete

anaqim

I got this far but am now getting this error message (from event.response)

{ "error" : { "status" : 400, "message" : "Malformed json" } }

my request looks like this:

local bdy=json.encode({uris={"spotify:track:6WK9dVrRABMkUXFLNlgWFh"}}) network.request("https://api.spotify.com/v1/me/player/play","PUT",gettrack,{headers={["Authorization"]="Bearer "..access\_token,["Content-Type"]="application/json"},body=bdy})

Any suggestions?

SOLVED! Made a mistake in the json.encode syntax.

Fixed the code above for future references

I got this far but am now getting this error message (from event.response)

{ "error" : { "status" : 400, "message" : "Malformed json" } }

my request looks like this:

local bdy=json.encode({uris={"spotify:track:6WK9dVrRABMkUXFLNlgWFh"}}) network.request("https://api.spotify.com/v1/me/player/play","PUT",gettrack,{headers={["Authorization"]="Bearer "..access\_token,["Content-Type"]="application/json"},body=bdy})

Any suggestions?

SOLVED! Made a mistake in the json.encode syntax.

Fixed the code above for future references