Token endpoint via PowerShell

Reply

Token endpoint via PowerShell

shaioshin
Casual Listener

Hey all. Anyone have success using Powershell to interact with the Spotify API? I’ve been able to capture to auth code but I’m getting a “something went wrong” back when trying to use Invoke-Restmethod to the /token endpoint. I’ve got the base64 client id/secret and the auth code but I can’t tell why it’s failing and there is no context from the response.

 

 

Operating System

Windows 10

 

 

3 Replies

PMental
Regular
I had the exact same issue. The alternative method of supplying them in the message body worked fine though. It's not mentioned for the token refresh but works there as well.

So I have it working, but I'd love to know why using the base64/header method refuses to work too. 

shaioshin
Casual Listener

Thanks. I’ll give that a shot.

Solid_Tester
Regular

Hi,


Could you please share the below concept for a newbie like myself:

 

How to properly achieve the base64 encoding of the
"client_id:client_secret"

that's needed in the step "1. Have your application request authorization"
from the Client Credentials Flow ?

 

I've done it using the certUtil tool from Windows command-line.
It reads the <client_id:client_secret> string from input.txt and writes the encoding into output.txt.

 

 

certUtil -encode input.txt output.txt

 


The encoded string contains a newline character in the output.txt,
which doesn't help the cURL request, if I remove it ...

certUtil.PNG


I get an Invalid Client error
(but I'm sure it has to do with the newline from the encoded output string).

Spotify's cURL command is:

curl -X "POST"
-H "Authorization: Basic <base64 encoded client_id:client_secret>"
-d grant_type=client_credentials
https://accounts.spotify.com/api/token



Much appreciated.

SUGGESTED POSTS