{"id":16676509,"url":"https://github.com/luketowers/php-shopify-api","last_synced_at":"2025-04-10T20:04:47.992Z","repository":{"id":56077116,"uuid":"120656003","full_name":"LukeTowers/php-shopify-api","owner":"LukeTowers","description":"Simple PHP wrapper for the Shopify API","archived":false,"fork":false,"pushed_at":"2024-06-01T08:47:59.000Z","size":8,"stargazers_count":34,"open_issues_count":0,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-08T21:39:50.020Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LukeTowers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-07T18:43:58.000Z","updated_at":"2024-09-17T07:47:46.000Z","dependencies_parsed_at":"2024-10-12T13:10:46.476Z","dependency_job_id":null,"html_url":"https://github.com/LukeTowers/php-shopify-api","commit_stats":{"total_commits":4,"total_committers":2,"mean_commits":2.0,"dds":0.25,"last_synced_commit":"1d927b2c7a1640e0931880376c524f6a7281cc0d"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeTowers%2Fphp-shopify-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeTowers%2Fphp-shopify-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeTowers%2Fphp-shopify-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LukeTowers%2Fphp-shopify-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LukeTowers","download_url":"https://codeload.github.com/LukeTowers/php-shopify-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248288027,"owners_count":21078827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T13:10:43.882Z","updated_at":"2025-04-10T20:04:47.972Z","avatar_url":"https://github.com/LukeTowers.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nA simple PHP wrapper around the [Shopify API](https://help.shopify.com/api/getting-started).\n\n## Installation\n\nInstall via [Composer](https://getcomposer.org/) by running `composer require luketowers/php-shopify-api` in your project directory.\n\n## Usage\n\nIn order to use this wrapper library you will need to provide credentials to access Shopify's API.\n\nYou will either need an access token for the shop you are trying to access (if using a [public application](https://help.shopify.com/api/getting-started/authentication#public-applications)) or an API Key and Secret for a [private application](https://help.shopify.com/api/getting-started/authentication#private-applications).\n\n## Examples\n\n#### Make an API call\n```php\nuse LukeTowers\\ShopifyPHP\\Shopify;\n\n// Initialize the client\n$api = new Shopify('exampleshop.myshopify.com', 'mysupersecrettoken');\n\n// Get all products\n$result = $api-\u003ecall('GET', 'admin/products.json');\n\n// Get the products with ids of '632910392' and '921728736' with only the 'id', 'images', and 'title' fields\n$result = $api-\u003ecall('GET', 'admin/products.json', [\n    'ids' =\u003e '632910392,921728736',\n    'fields' =\u003e 'id,images,title',\n]);\n\n// Create a new \"Burton Custom Freestyle 151\" product\n$result = $api-\u003ecall('POST', 'admin/products.json', [\n    'product' =\u003e [\n        \"title\"        =\u003e \"Burton Custom Freestyle 151\",\n        \"body_html\"    =\u003e \"\u003cstrong\u003eGood snowboard!\u003c/strong\u003e\",\n        \"vendor\"       =\u003e \"Burton\",\n        \"product_type\" =\u003e \"Snowboard\",\n        \"tags\"         =\u003e 'Barnes \u0026 Noble, John's Fav, \"Big Air\"',\n    ],\n]);\n```\n\n#### Use Private Application API Credentials to authenticate API requests\n```php\nuse LukeTowers\\ShopifyPHP\\Shopify;\n\n$api = new Shopify($data['shop'], [\n    'api_key' =\u003e '...',\n    'secret'  =\u003e '...',\n]);\n```\n\n#### Use an access token to authenticate API requests\n```php\nuse LukeTowers\\ShopifyPHP\\Shopify;\n\n$storedToken = ''; // Retrieve the stored token for the shop in question\n$api = new Shopify('exampleshop.myshopify.com', $storedToken);\n```\n\n#### Request an access_token for a shop\n```php\nuse LukeTowers\\ShopifyPHP\\Shopify;\n\nfunction make_authorization_attempt($shop, $scopes)\n{\n    $api = new Shopify($shop, [\n        'api_key' =\u003e '...',\n        'secret'  =\u003e '...',\n    ]);\n\n    $nonce = bin2hex(random_bytes(10));\n\n    // Store a record of the shop attempting to authenticate and the nonce provided\n    $storedAttempts = file_get_contents('authattempts.json');\n    $storedAttempts = $storedAttempts ? json_decode($storedAttempts) : [];\n    $storedAttempts[] = ['shop' =\u003e $shop, 'nonce' =\u003e $nonce, 'scopes' =\u003e $scopes];\n    file_put_contents('authattempts.json', json_encode($storedAttempts));\n\n    return $api-\u003egetAuthorizeUrl($scopes, 'https://example.com/handle/shopify/callback', $nonce);\n}\n\nheader('Location: ' . make_authorization_attempt('exampleshop.myshopify.com', ['read_product']));\ndie();\n```\n\n#### Handle Shopify's response to the authorization request\n```php\nuse LukeTowers\\ShopifyPHP\\Shopify;\n\nfunction check_authorization_attempt()\n{\n    $data = $_GET;\n\n    $api = new Shopify($data['shop'], [\n        'api_key' =\u003e '...',\n        'secret'  =\u003e '...',\n    ]);\n\n    $storedAttempt = null;\n    $attempts = json_decode(file_get_contents('authattempts.json'));\n    foreach ($attempts as $attempt) {\n        if ($attempt-\u003eshop === $data['shop']) {\n            $storedAttempt = $attempt;\n            break;\n        }\n    }\n\n    return $api-\u003eauthorizeApplication($storedAttempt-\u003enonce, $data);\n}\n\n$response = check_authorization_attempt();\nif ($response) {\n    // Store the access token for later use\n    $response-\u003eaccess_token;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluketowers%2Fphp-shopify-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluketowers%2Fphp-shopify-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluketowers%2Fphp-shopify-api/lists"}