I am trying to build a custom Shopify app in my Shopify admin.
I am using Shopify’s official PHP library.
I have successfully initialized the library.
Now when I try to connect to the API I am getting the following error:
Fatal error: Uncaught ShopifyExceptionMissingArgumentException: Missing Authorization key in headers array in /www/doc/www.sozialstar.de/www/script/vendor/shopify/shopify-api/src/Auth/OAuth.php:226 Stack trace: #0 /www/doc/www.sozialstar.de/www/script/vendor/shopify/shopify-api/src/Utils.php(160): ShopifyAuthOAuth::getCurrentSessionId(Array, Array, true) #1 /www/doc/www.sozialstar.de/www/script/shopifytest.php(29): ShopifyUtils::loadCurrentSession(Array, Array, true) #2 {main} thrown in /www/doc/www.sozialstar.de/www/script/vendor/shopify/shopify-api/src/Auth/OAuth.php on line 226
Here is my PHP code:
$requestHeaders = array('api_version'=>'2022-10', 'X-Shopify-Access-Token'=>'mytoken');
$requestCookies = array();
$isOnline = true;
$this->test_session = Utils::loadCurrentSession(
$requestHeaders,
$requestCookies,
$isOnline
);
I am doing this based on Shopify API docs.
Why is it not working?
2
Answers
It seems like the Shopify API for PHP expects you to set the
Authorization
header field/ doesn’t supportX-Shopify-Access-Token
. Try this instead:I am also getting the same issue. The problem is in below file.
vendor/firebase/php-jwt/src/JWT.php
See public static function decode(). The first parameter for this function is $jwt and it is pure access token which we passing in header. Ex : XXX_XXXXXXXXXX
Then see below code in above function.
The issue is it is exploding the – sign. But the $jwt contain value like XXX_XXXXXX. Actually it is looking for a value lile XXXXXX.XXXXXX.XXXXXX
Seems we have to encode the access token in header or should set something to encode the header. Any idea guys?
Thank You!