Quickstart fail

Using the Getting an access token for your API quickstart, the cURL command:

curl --request POST \
  --url https://xxxxx.eu.auth0.com/oauth/token \
  --header 'content-type: application/json' \
  --data '{"client_id":"xxxxx","client_secret":xxxx-xxxx","audience":"https://xxxx.eu.auth0.com/api/v2/","grant_type":"client_credentials"}'

fails with an invalid json response…
The above is copied directly from the quickstart (with the obvious change in the credentials). So, what’s wrong?

Hi @h3llo,

Welcome to the Auth0 Community!

As the error says, your JSON is invalid. You are missing a quote in your client_secret value.

Sometimes it’s helpful to write your JSON in a code editor like VS code which can help to validate the data’s formatting.

1 Like

hmm no, that was me removing the actual secret and taking the quote, but nm. I will look at another solution instead.

@h3llo - Which quickstart are you working off of?

According to Get Access Tokens the content-type should be x-www-form-urlencoded rather than application/json like:

curl --request POST \
  --url 'https://YOUR_DOMAIN/oauth/token' \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data grant_type=client_credentials \
  --data client_id=YOUR_CLIENT_ID \
  --data client_secret=YOUR_CLIENT_SECRET \
  --data audience=YOUR_API_IDENTIFIER

Does that help at all?


Gotcha, that was just the first thing I noticed and would have returned that same error.

Can you try what @tyf mentioned and let us know if that works?

Additionally, can you please post a link to the doc you got this code snippet from? If there is an issue with the doc I’d like to update it.


Thanks for the info.
I was working off the ‘API Explorer Application’ quickstart. Was having trouble getting the C# quickstart to work and then the cURL version.

cURL was a GitBash fail when I looked closer, which I resolved.
However, I was struggling for ages with the C# quick start.
For those who come upon it and wonder what the heck (or maybe that was just me) lol…

The RestClient in the quickstart is deprecated. Latest version (107.x) does not use synchronous calls or any of the Header/Parameter settings. Also it no longer will return a IRestResponse.

Below is my working version using async if it helps anyone:

var client = new RestClient("https://YOUR_AUTH0_DOMAIN");

var request = new RestRequest("oauth/token", Method.Post);

request.AddStringBody("{\"client_id\":\"YOUR_CLIENT_ID\",\"client_secret\":\"YOUR_CLIENT_SECRET\",\"audience\":\"https://YOUR_API.eu.auth0.com/api/v2/\",\"grant_type\":\"client_credentials\"}", DataFormat.Json);

var response = await client.ExecuteAsync(request);