Shopify generating access token giving curl error

Hello there,

We have a live Shopify app and for the development purpose we have multiple development stores. All our app changes are tested using these stores. However for testing purpose we uninstalled and reinstalled our Shopify app but we found some issues getting the access token for these Development stores. There is no access token generation issues for our actual subscribing clients. Only for development store we are facing the issue.

Below is my curl script to get access token:

$accessqueryparameters = array(
  "Content-type" => "application/json", // Tell Shopify that we're expecting a response in JSON format
  "client_id" => $appclientid', // Your API key
  "client_secret" => $appsharedsecret', // Your app credentials (secret key)
  "code" => $code // Grab the access key from the URL
);
// Generate access token URL
$accesstokenURL = "https://".$shop."/admin/oauth/access_token";

// Configure curl client and execute request
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $accesstokenURL);
curl_setopt($ch, CURLOPT_FAILONERROR, true); // Required for HTTP error codes to be reported via our call to curl_error($ch)

curl_setopt($ch, CURLOPT_POST, count($accessqueryparameters));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($accessqueryparameters));
$accessqueryresultJSON = curl_exec($ch);
 if (curl_errno($ch)) {
    echo $error_msg = curl_error($ch);
 }
curl_close($ch);

$accesstokenresultarray = json_decode($accessqueryresultJSON);
$accesstoken = $accesstokenresultarray['access_token'];

$error_msg is coming as

The requested URL returned error: 400 Bad Request

and $accesstoken is NULL.

It was all working fine. Not sure what happened.

Any help would be appreciated.

Hi,

Check if the following variables have been properly set:

  1. $shop
  2. $accessqueryparameters

Hello @jazz-jay ,

YES

All variables are having correct values