Hardik Panot
Hardik Panot

Reputation: 21

Missing Authorization key in headers array in laravel Shopify app using shopify cli

I had to install shopify-cli for develop shopify app with laravel. installation and test app are created successfully but when am i calling the API of shopify in Laravel app i got this error.

I am check header but no authorisation token pass. So my question how to get authenticate token get in Laravel starter app and call API of Shopify and i was follow PHP guide REST Admin API reference but without session i can not access shopify REST Admin API reference.

my code show like this...

Route::get('/rest-example', function (Request $request) {
/** @var AuthSession */
// $session = $request->get('shopifySession'); // Provided by the shopify.auth middleware, guaranteed to be active
    $session = OAuth::callback(
        $request->cookie(),
        $request->query(),
        ['App\Lib\CookieHandler', 'saveShopifyCookie'],
    );
    $client = new Rest($session->getShop(), $session->getAccessToken());
    $result = $client->get('products', [], ['limit' => 5]);

    return response($result->getDecodedBody());
})->middleware('shopify.auth:online')->name('rest-api');

Upvotes: 2

Views: 2743

Answers (1)

Serhii Chepel
Serhii Chepel

Reputation: 11

I think you want to create Custom App (not embedded) for your store. You can read here about difference. I spent the whole day searching for solutions until get the idea.

All you need to do is to create a Custom App in your store, then get Admin API access token with you can use for REST API calls.

Here is my small example how I get it.

use Shopify\Clients\Rest;

Route::get('/test', function(Request $request) {
    $client = new Rest(
        env('SHOPIFY_APP_HOST_NAME'),
        env('SHOPIFY_APP_ADMIN_ACCESS_TOKEN') // shpat_***
    );

    dd($client->get('products')->getDecodedBody());
});

Upvotes: 1

Related Questions