Focuses on API authentication, access scopes, and permission management.
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 );
…
Solved! Go to the solution
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.
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.
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
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 ?
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