I’m trying to authenticate with Spotify’s Web API using client credentials flow but keep running into issues. Every time I make the authentication request, I get a 400 error saying the grant_type is unsupported, even though I’m setting it to client_credentials like the docs say.
The error message I keep getting is:
400 Bad Request: {"error":"unsupported_grant_type","error_description":"grant_type must be client_credentials, authorization_code or refresh_token"}
Here’s my authentication function:
sub fetch_auth_token {
my $params = {grant_type => "client_credentials"};
my $request = HTTP::Request->new("POST", TOKEN_ENDPOINT, [
"Content-Type" => "application/x-www-form-urlencoded",
"Authorization" => "Basic $ENV{SPOTIFY_AUTH_B64}",
], encode_utf8 encode_json $params);
my $response = $ua->request($request);
if($response->is_success) {
return %{decode_json $response->content}{"access_token"};
} else {
die $response->status_line . ": " . $response->content . "\n";
}
}
I’ve double checked my client credentials and they seem correct. What could be causing this grant_type error?