Ad

Guzzle HTTP Client And Shopify Access Token Exception

I'm getting Client error: POST https://testing-shop.myshopify.com/admin/oauth/access_token resulted in a 400 Bad Requestwhile trying to exchange temporary code for access token in Shopify. I'm using the latest version of Guzzle HTTP client and in Chrome, Windows 8.1. What's even more weird is that it worked before.

$client = new Client();
    try{
    $response = $client->request(
        'POST', 
        "https://{$store}/admin/oauth/access_token",
        [
            'form_params' => [
                'client_id' => $api_key,
                'client_secret' => $secret_key,
                'code' => $query['code']
            ]
        ]
    );
    }catch(Exception $e){
        var_dump($e);
    }

I also checked all my variables ($api_key, $secret_key)... and they're good which means they have values. What could be the problem here that I missed? TIA

EDIT:

It turned out to be the problem when registering the web hook .

$response = $client->request(
        'POST', 
        "https://{$store}/admin/webhooks.json",
        [
            'webhook' => [
                'topic' => 'app/uninstalled',
                'address' => 'http://example.com/shopify/uninstall',
                'format' => 'json'
            ]
        ]
    );

This code causes the error but I'm not though why.

Ad

Answer

Think I've got it. And it fits with having worked then stopped working:

After July 1st 2018, apps will be required to use HTTPS webhook addresses.

See: https://help.shopify.com/en/api/getting-started/webhooks

Ad
source: stackoverflow.com
Ad