skip to Main Content

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


  1. It seems like the Shopify API for PHP expects you to set the Authorization header field/ doesn’t support X-Shopify-Access-Token. Try this instead:

    $requestHeaders = array(
                           'api_version'=>'2022-10', 
                           'Authorization'=>'Bearer YOUR_ACCESS_TOKEN'
                          );
    
    Login or Signup to reply.
  2. 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.

    $tks = explode('.', $jwt);
        if (count($tks) !== 3) {
            throw new UnexpectedValueException('Wrong number of segments');
        }
    

    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!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search