Issue with generating Access Tokens in sandbox environment

(mrsai) #1

Hi, I have an issue trying to get an access token from

According to the docs, I use my key i get from the dashboard for client_id, and secret as client_secret.
I set the content-type to application/x-www-form-urlencoded.

However the response from the serever is as follows:

{“error”:“access_denied”,“error_description”:“Invalid application credentials.”}

Ive tried this several ways including using client_id and client_secret as header parameters… i tried setting them as a json obejct in the body… but either way doesnt seem to work.

Here is the code i used in java:

        URL url = new URL("");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        String data = "";
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("client_id", "<CLIENT ID>");
        jsonObj.put("client_secret", "<CLIENT SECRET>");
        jsonObj.put("grant_type", "client_credentials");
        data = jsonObj.toString();
            byte[] outputInBytes = data.getBytes("UTF-8");
            OutputStream os = conn.getOutputStream();
            os.write( outputInBytes );    
            System.out.println("Message:" + conn.getResponseMessage());
            //System.out.println("Location:" + conn.getHeaderField("Location"));
            BufferedReader br = new BufferedReader(new InputStreamReader(

	String output;
	System.out.println("Output from Server .... \n");
	while ((output = br.readLine()) != null) {


(Stephen Ausman) #2

Hey sanziosan,

I think the problem you’re running into is due to the content body being formatted as a JSON (jsonObj.toString()) instead of form encoded. I would try one of two things:

Option 1: Change the Content-Type header to application/json. (I think this should work, if not try Option 2)

Option 2: Form-encode the request body instead of sending a JSON string. See this example.

Hopefully one of those works! Let us know if you still have trouble.