Html Error 400 for access_token

Highlighted
Shopify Partner
1 0 0

Hello,
I get many times (but not always) html error 400 when trying to access a url like the following
requestUrl https://blue-box-supplies.myshopify.com/admin/oauth/access_token 
payload {"client_id":"xx","client_secret":"xxx","code":"xxx"}

Using java:

URL url = new URL(requestUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
// connection.setReadTimeout(60000);
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json");
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
writer.write(payload);
writer.close();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
connection.disconnect();

0 Likes
Community Manager
Community Manager
574 35 67

Hi @Ron9,

 

As you likely already know, a 400 status means the server could not understand the request. I took a look in our logs and it was not initially obvious to me what the issue was. The code and client_secret do not get logged, so I would start your debugging journey with ensuring these values were correct. When I attempt a bad request, I actually get a message in the response body that gives me a clue as to what the issue might be. "Missing or invalid client secret" for example.

 

I hope that gives you a starting point in your debugging.

 

Cheers

0 Likes