httplast.fm

"FAILED Incorrect protocol version (missing clientID/version/username)", LastFM API


I'm trying to add scrobbles to my LastFM account by using their API. I managed to do the Auth and GET methods, but when trying to use the "track.scrobble" method by using this setup (The words in the curly Brackets get obviously replaced before sending the request):

URL: http://ws.audioscrobbler.com/2.0/?method=track.scrobble&api_key={YOUR_API_KEY}&sk={SESSION_KEY}&api_sig{API_SIGNATURE}&user={USERNAME}

Headers: Content-Type: application/x-www-form-urlencoded

Body: "artist=Kanye+West&timestamp={TIMESTAMP}&track=Heartless"

Method = POST

I get an OK Response (200), but an error from LastFm:

FAILED Incorrect protocol version (missing clientID/version/username)

I'm sorry if this is a stupid question, but I'm very inexperienced working with APIs. Any help is appreciated!!

EDIT:

The HTTP Request Itself:

var body = "method=track.scrobble&api_key={YOUR_API_KEY}&sk={SESSION_KEY}&api_sig{API_SIGNATURE}&artist=Daniel+Caesar&timestamp={TIMESTAMP}&track=Pseudo".format(
            {
                "YOUR_API_KEY" : APIKey,
                "SESSION_KEY" : session_key,
                "TIMESTAMP" :  str(OS.get_unix_time() - 31),
                "API_SIGNATURE" : ConstructMD5Hash()
            }
        )
    HTTP.request(
        url,
        headers,
        true,
        HTTPClient.METHOD_POST,
        body
    )
    HTTP.connect("request_completed",self,"replace_tag")

The ConstructMD5Hash for the API_SIGNATURE:

func ConstructMD5Hash() -> String:
return LastFM_MD5_Hash_Template.format(
    {
        "YOUR_API_KEY" : APIKey,
        "REQUEST_TOKEN" : request_token,
        "MY_SECRET" : APISecret,
    }
).md5_text()

The Full Response by LAST.FM:

[Server: openresty/1.13.6.2, Date: Mon, 30 Jan 2023 17:10:21 GMT, Content-Type: text/plain; charset=utf-8, Transfer-Encoding: chunked, Access-Control-Allow-Methods: POST, GET, OPTIONS, Access-Control-Allow-Origin: *, Access-Control-Max-Age: 86400, Via: 1.1 google] FAILED Incorrect protocol version (missing clientID/version/username)

Btw I am using Godot 3.5.1, if that's of any use


Solution

  • Looks like Last.FM generates this error if the body lacks required parameters.

    In your case the URL should be "http://ws.audioscrobbler.com/2.0/" only (this is a POST method).

    And the body should be:

    "method=track.scrobble&api_key={YOUR_API_KEY}&sk={SESSION_KEY}&api_sig={API_SIGNATURE}artist=Kanye+West&timestamp={TIMESTAMP}&track=Heartless"