I am trying to connect to Shopify Rest Admin API using PHP and I am using Shopify API’s PHP library and I initialize successfully like this:
ShopifyContext::initialize(
'key',
'secret',
'scope_1, scope_2',
'https://example.com',
new FileSessionStorage('/tmp/php_sessions'),
'2022-10',
);
But when I try to make a request like this:
$this->test_session = Utils::loadCurrentSession(
$requestHeaders,
$requestCookies,
$isOnline
);
Webhookv2::webhooks(
$this->test_session, // Session
[], // Url Ids
[], // Params
);
I get the following error:
Fatal error: Uncaught TypeError: Argument 1 passed to ShopifyUtils::loadCurrentSession() must be of the type array, null given, called in /www/doc/www.example.com/www/script/index.php on line 45 and defined in /www/doc/www.example.com/www/script/vendor/shopify/shopify-api/src/Utils.php:158 Stack trace: #0 /www/doc/www.example.com/www/script/index.php(45): ShopifyUtils::loadCurrentSession(NULL, NULL, NULL) #1 {main} thrown in /www/doc/www.example.com/www/script/vendor/shopify/shopify-api/src/Utils.php on line 158
What am I missing?
P.S.
The code in the Utils.php file (part of Shopify PHP library) that corresponds to the three session variables above:
/**
* Loads the current user's session based on the given headers and cookies.
*
* @param array $rawHeaders The headers from the HTTP request
* @param array $cookies The cookies from the HTTP request
* @param bool $isOnline Whether to load online or offline sessions
*
* @return Session|null The session or null if the session can't be found
* @throws ShopifyExceptionCookieNotFoundException
* @throws ShopifyExceptionMissingArgumentException
*/
public static function loadCurrentSession(array $rawHeaders, array $cookies, bool $isOnline): ?Session
{
$sessionId = OAuth::getCurrentSessionId($rawHeaders, $cookies, $isOnline);
return Context::$SESSION_STORAGE->loadSession($sessionId);
}
2
Answers
TheĀ
loadCurrentSession
method requires$requestHeaders
to be an array (docs).Make sure the
$requestHeaders
variable you pass as argument is indeed an array. Something like:I am also stuck in above question. Please some one help!
Please tell how to set the values to the sub,exp,nbf,iat elements in below code.