PHP API - LoadCurrentSession

Topic summary

Developers are encountering a TypeError when calling Shopify\Utils::loadCurrentSession() in the PHP API library. The error indicates that the method expects array arguments but receives null values instead.

Core Issue:

  • The loadCurrentSession() method requires three array parameters: $requestHeaders, $requestCookies, and a boolean flag
  • Users are passing null or improperly formatted arrays, causing fatal errors

Attempted Solutions:

  • One user suggested formatting $requestHeaders with api_version and Authorization: Bearer [TOKEN]
  • Another attempted using X-Shopify-Access-Token header but encountered “Missing Authorization key” errors

Unresolved Questions:

  • How to obtain an access token from Client ID and Secret ID for private apps installed via distribution links
  • Difference between Utils::loadCurrentSession() and Context::initialize() methods
  • Whether access tokens can be retrieved through the Context::initialize() method
  • New errors emerging around OpenSSL symmetric key requirements

Status: The discussion remains open with no definitive solution. Multiple users report similar authentication/token retrieval challenges when working with Shopify’s private app configuration.

Summarized with AI on November 9. AI used: claude-sonnet-4-5-20250929.

Hi

I have been at this all day, so it’s time to ask for some help!

I am getting the following output when I run the script below, I am sure it’s basic!?! I have looked at permissions, file dir and everything seems ok. Any ideas or suggestions welcome:

[11-Nov-2022 17:09:46 UTC] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Shopify\Utils::loadCurrentSession() must be of the type array, null given, called in /home/############s/apps/discounts/apitest.php on line 27 and defined in /home/############s/apps/discounts/vendor/shopify/shopify-api/src/Utils.php:158
Stack trace:
#0 /home/############s/apps/discounts/apitest.php(27): Shopify\Utils::loadCurrentSession(NULL, NULL, NULL)
#1 /home/############s/apps/discounts/index.php(5): include_once('/home/############...')
#2 {main}
  thrown in /home/############s/apps/discounts/vendor/shopify/shopify-api/src/Utils.php on line 158
[11-Nov-2022 17:09:47 UTC] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Shopify\Utils::loadCurrentSession() must be of the type array, null given, called in /home/############s/apps/discounts/apitest.php on line 27 and defined in /home/############s/apps/discounts/vendor/shopify/shopify-api/src/Utils.php:158
Stack trace:
#0 /home/############s/apps/discounts/apitest.php(27): Shopify\Utils::loadCurrentSession(NULL, NULL, NULL)
#1 /home/############s/apps/discounts/index.php(5): include_once('/home/############...')
#2 {main}
  thrown in /home/############s/apps/discounts/vendor/shopify/shopify-api/src/Utils.php on line 158

And here’s the script, thanks in advance for any nudge in the right direction!

Gareth

…
Context::initialize(
    $_ENV['SHOPIFY_API_KEY'],
    $_ENV['SHOPIFY_API_SECRET'],
    $_ENV['SHOPIFY_APP_SCOPES'],
    $shop_url,
    new FileSessionStorage(__DIR__.'/tmp/php_sessions'), // This path works fine - creates dir
    '2022-10',
    true,
    false,
);

use Shopify\Rest\Admin2022_10\PriceRule;
use Shopify\Utils;
$this->test_session = Utils::loadCurrentSession( // Seems to fail here -- see log output
    $requestHeaders,
    $requestCookies,
    $isOnline
);
…

The loadCurrentSession method has the following signature:

Shopify\Utils::loadCurrentSession(Array, Array, true)

So $requestHeaders must be an array. And so does $requestCookies. Since your code snippet doesn’t show how you create those variables, I can’t help you further.

Did you found how ?

I’m currently stuck with

$requestHeaders = array(
‘api_version’ => ‘2023-04’,
‘X-Shopify-Access-Token’ => $accessToken
);

$requestCookies = array();
$isOnline = true;

$session = Shopify\Utils::loadCurrentSession(
$requestHeaders,
$requestCookies,
$isOnline
);

returning Missing Authorization key in headers

Hey everyone,

I’m getting the same issue when i’m trying to use Shopify\Utils::loadCurrentSession from php librairy

There is the used code

...
...
        $requestHeaders = [
            'api_version' => '2023-04',
            'X-Shopify-Access-Token' => '',
        ];

        $requestCookies = [];

        $session = Utils::loadCurrentSession(
            $requestHeaders,
            $requestCookies,
            true
        );

Where the difference beetwen

Utils::loadCurrentSession method and
Context::initialize method

Context::initialize(
            apiKey: $_ENV['SHOPIFY_API_KEY'],
            apiSecretKey: $_ENV['SHOPIFY_API_SECRET'],
            scopes: $_ENV['SHOPIFY_APP_SCOPES'],
            hostName: $_ENV['SHOPIFY_APP_HOST_NAME'],
            sessionStorage: new FileSessionStorage('/tmp/php_sessions'),
            apiVersion: $_ENV['SHOPIFY_API_VERSION'],
            isEmbeddedApp: $_ENV['SHOPIFY_EMBEDDED_APP'],
            isPrivateApp: $_ENV['SHOPIFY_PRIVATE_APP'],
        );

Can i get a store token via the Context::initialize method ? how please ?

Thank you a lot.

Try:

$requestHeaders = [
	'api_version' => '2023-04',
	'Authorization' => "Bearer YOUR_TOKEN_HERE",
];

I’ve just managed to get that far, and now I’m stuck on the next error.

Hi Susanp,

thank you for replying my issue.

i can’t send the following request because i don’t have an access token.

To you explain more the problem in give you more details:

  1. First i create a custom application via the partner portal, then i configure the application which allows me to have an ID client and an ID scret.

  2. Then i install the private application in concerned store via distribution link. This means that when creating and configuring the application, I do not have an access token.

There are way to retrieve an access token from Client ID and Secret ID ? or how can i do ?

I hope you could understand my problem

Thank you so much .

Hi Susanp,

I have tried this after I got a new error below

Fatal error: Uncaught TypeError: Key material must be a string, resource, or OpenSSLAsymmetricKey

Please help to resolve the problem.

Thanks