Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

PHP API - LoadCurrentSession

Solved

PHP API - LoadCurrentSession

GarethWyn
Shopify Partner
12 0 5

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 );
 
Accepted Solution (1)

genevievem
Shopify Partner
5 1 1

This is an accepted solution.

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.

View solution in original post

Replies 7 (7)

genevievem
Shopify Partner
5 1 1

This is an accepted solution.

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.

Mammouth
Tourist
15 0 2

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

atom117
New Member
9 0 0

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
        );
atom117
New Member
9 0 0

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.
susanp
Shopify Partner
2 0 0

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.

atom117
New Member
9 0 0

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.

 

Capture d’écran 2023-07-22 à 16.27.34.png

 

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 .

Naeemakhter
Shopify Partner
1 0 0

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