1. Go to this page and download the library: Download webtize/shopify-graphql-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webtize / shopify-graphql-sdk example snippets
use ShopifyGraphQL\ClientFactory;
// Simple setup with auto-discovery
$client = ClientFactory::create(
'your-store.myshopify.com', // or just 'your-store'
'your-access-token-here'
);
// Get shop information
$response = $client->getShopInfo();
if ($response->isSuccessful()) {
$shop = $response->get('shop');
echo "Shop: " . $shop['name'];
}
use ShopifyGraphQL\Products;
$products = new Products($client);
// List products
$response = $products->list(10);
foreach ($response->get('products.edges', []) as $edge) {
echo $edge['node']['title'] . "\n";
}
// Get single product
$product = $products->get('gid://shopify/Product/123');
echo $product->get('product.title');
// Create product
$newProduct = $products->create([
'title' => 'New Product',
'productType' => 'Electronics',
'vendor' => 'ACME Corp'
]);