Focuses on API authentication, access scopes, and permission management.
Hello
I'm fairly new to coding agains Shopify REST API.
Until today I used a third party library to talk to shopify's REST API because I'm not able to get the original library up and running. Here the links I've read and followed.
- https://shopify.dev/docs/api/admin-rest
- https://shopify.dev/docs/apps/auth/admin-app-access-tokens
-- I tried the Curl REST Example and got this working as described in the docu.
Here what I have in code
- In composer.json I have
"shopify/shopify-api": "^5.1"
installed
Here the sample code, which is causing the error message
<?php
declare(strict_types=1);
namespace ShopifyConnector\ShopifySdk\Request;
use Shopify\Rest\Admin2023_07\Product;
use Shopify\Utils;
class ProductTest
{
public function getAll()
{
Context::initialize(
'MY_API_ID_AS_SHOWN_IN_SHOPIFY_APP_ADMIN_SECTION',
'SAME_TOKEN_AS_IN_CURL_EXAMPLE',
['read_products'],
'MY_DEV_SHOP.myshopify.com',
new FileSessionStorage(),
);
$requestHeaders = [
'Content-Type' => 'application/json',
'X-Shopify-Access-Token' => 'SAME_TOKEN_AS_IN_CURL_EXAMPLE',
];
$requestCookies = [];
$isOnline = true;
$test_session = Utils::loadCurrentSession(
$requestHeaders,
$requestCookies,
$isOnline
);
$p = Product::all(
$test_session, // Session
);
var_dump($p);
die();
}
}
This code causes an
Shopify\Exception\MissingArgumentException
with this message
Missing Authorization key in headers array
I dug a bit deeper into the library and found that I should have provided an authorisation header with some kind of Bearer token?
Can someone help me, please? And tell me what I'm doing wrong and what I'm missing?
Jus a bit background about the App I'm building: It is an self hosted PHP application which reads products and orders from shopify and uses these data to tell our own production team what what they should focus on.
Who can help, please?
Thanks in advance for the help provided.
Hey @dj_thossi
Thanks for all the details. Please copy them over to an issue here to get eyes from the PHP folks: https://github.com/Shopify/shopify-api-php/issues
Scott | Developer Advocate @ Shopify
Done. Here the link to it: https://github.com/Shopify/shopify-api-php/issues/295