Announcements

Help Wizard

Step 1

NEXT STEP

Can't get access token for my app

Can't get access token for my app

Plan

Premium

Operating System

(Windows 10,etc.)

 

My Question or Issue

I'm trying to obtain an access token for my app. This is the type of cURL request I use to do it:

curl -X POST "https://accounts.spotify.com/api/token" \ -H "Content-Type: application/x-www-form-urlencoded" \-H "Content-length: <content-length>" \-d "grant_type=client_credentials&client_id=your-client-id&client_secret=your-client-secret"

This is the error I get:
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>411 Length Required</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Length Required</h1>
<h2>POST requests require a <code>Content-length</code> header.</h2>
<h2></h2>
</body></html>
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL
curl: (3) URL using bad/illegal format or missing URL

These are the details of the version of cURL I'm using:

curl 8.0.1 (Windows) libcurl/8.0.1 Schannel WinIDN
Release-Date: 2023-03-20
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS HSTS HTTPS-proxy IDN IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI threadsafe Unicode UnixSockets

Please tell me what I'm doing wrong and how to fix this.

 

Reply
3 Replies

I tried it before without the "context-length", as per the instructions in https://developer.spotify.com/documentation/web-api/tutorials/getting-started#request-an-access-toke..., But I was met with the error: 

 

<html><head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>411 Length Required</title> </head> <body text=#000000 bgcolor=#ffffff> <h1>Error: Length Required</h1> <h2>POST requests require a <code>Content-length</code> header.</h2> <h2></h2> </body></html> curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL

 

It was because of this error that I tried adding the "content-length" header.

I don't know what you are doing different, but the following does work for me (I have changed some characters of my IDs before posting):

 

 

curl -X POST "https://accounts.spotify.com/api/token" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&client_id=d61ffce7fef1327eb07b0d50c2ef1362&client_secret=1d9930fa93524cdd7adfa2119f579f1f"

 

 

 

 

Suggested posts