{"id":25929528,"url":"https://github.com/robwittman/shopify-php-sdk","last_synced_at":"2025-04-06T01:09:41.857Z","repository":{"id":46685837,"uuid":"56446796","full_name":"robwittman/shopify-php-sdk","owner":"robwittman","description":"PHP SDK for development with the Shopify API","archived":false,"fork":false,"pushed_at":"2024-06-13T12:52:36.000Z","size":483,"stargazers_count":67,"open_issues_count":22,"forks_count":40,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T00:07:23.633Z","etag":null,"topics":["ecommerce","php","php-sdk","shopify","shopify-api"],"latest_commit_sha":null,"homepage":null,"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/robwittman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-17T16:32:16.000Z","updated_at":"2025-01-06T09:40:47.000Z","dependencies_parsed_at":"2022-08-24T10:10:46.289Z","dependency_job_id":null,"html_url":"https://github.com/robwittman/shopify-php-sdk","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robwittman%2Fshopify-php-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robwittman%2Fshopify-php-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robwittman%2Fshopify-php-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robwittman%2Fshopify-php-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robwittman","download_url":"https://codeload.github.com/robwittman/shopify-php-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419861,"owners_count":20936012,"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":["ecommerce","php","php-sdk","shopify","shopify-api"],"created_at":"2025-03-03T22:07:48.459Z","updated_at":"2025-04-06T01:09:41.824Z","avatar_url":"https://github.com/robwittman.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/robwittman/shopify-php-sdk.svg?branch=master)](https://travis-ci.org/robwittman/shopify-php-sdk)\n\n# Shopify PHP SDK\n\nThis SDK was created to enable rapid efficient development using Shopify's API.\n\n## Installation\n\nEasily install this package with composer\n\n```shell\ncomposer require robwittman/shopify-php-sdk\n```\n\nBefore you can start using this SDK, you have to create a \u003ca href=\"https://partners.shopify.com/\"\u003eShopify Application\u003c/a\u003e\nYou can now use the API key and secret to generate access tokens, which can then access a stores data\n\n## Initialization\n\nTo initialize the Api Client:\n\n```php\n$client = new Shopify\\Api(array(\n    'api_key' =\u003e '\u003capi_key\u003e',\n    'api_secret' =\u003e '\u003capi_secret\u003e',\n    'myshopify_domain' =\u003e 'store.myshopify.com',\n    'access_token' =\u003e '\u003cstore_access_token\u003e'\n));\n```\n\nIf you are using a Private App for use on an individual store:\n```php\n$client = new Shopify\\PrivateApi(array(\n    'api_key' =\u003e '\u003capi-key\u003e',\n    'password' =\u003e '\u003cpassword\u003e',\n    'shared_secret' =\u003e '\u003cshared-secret\u003e',\n    'myshopify_domain' =\u003e '\u003cstore\u003e.myshopify.com'\n));\n```\n\nOnce the client is initialized, you can then create a service, and use it to communicate with the api\n\n### Reading\n\n```php\n$service = new Shopify\\Service\\ProductService($client);\n$service-\u003eall(); #Fetch all products, with optional params\n$service-\u003eget($productId); # Get a single product\n$service-\u003ecount(); # Count the resources\n```\n\n### Creating\n\n```php\n$service = new Shopify\\Service\\ProductService($client);\n$product = new Shopify\\Object\\Product();\n# Set some product fields\n$product-\u003etitle = 'Test Product';\n$product-\u003evendor = 'Printer';\n\n$service-\u003ecreate($product);\n```\n\n### Updating\n\n```php\n$service = new Shopify\\Service\\ProductService($client);\n$product = $service-\u003eget($productId);\n# Set some product fields\n$product-\u003etitle = 'Test Product';\n$product-\u003evendor = 'Printer';\n\n$service-\u003eupdate($product);\n```\n\n### Deleting\n```php\n$service = new Shopify\\Service\\ProductService($client);\n$service-\u003edelete($productId);\n```\n\n### GraphQL\n\n#### Query\n```php\n$service = new Shopify\\Service\\GraphQLService($client);\n$service-\u003egraph(\n  '{\n    products(query: \"created_at:\u003c2019\", first: 5) {\n      edges {\n        node {\n          title\n          description\n        }\n      }\n    }\n  }'\n);\n```\n\n#### Mutation\n```php\n$service = new Shopify\\Service\\GraphQLService($client);\n$service-\u003egraph(\n  'mutation productCreate($input: ProductInput!){\n    productCreate(input: $input) {\n      product {\n        id\n      }\n    }\n  }',\n  ['input' =\u003e ['title' =\u003e 'Sweet new product','productType' =\u003e 'Snowboard','vendor' =\u003e 'JadedPixel']]\n);\n```\n\n## Authentication\n\nAuthentication to Shopify's API is done through access tokens, which are obtained through OAuth. To get a\ntoken, there is a helper library packaged with this client\n\n```php\n$client = new Shopify\\Api($params);\n$helper = $client-\u003egetOAuthHelper();\n\n$redirectUri = 'https://localhost/install.php';\n$scopes = 'write_products,read_orders,...';\n\n$authorizationUrl = $helper-\u003egetAuthorizationUrl($redirectUri, $scopes);\nheader(\"Location: {$authorizationUrl}\");\n```\n\nAt your `redirect_uri`, instantiate the helper again to get an access token\n```php\n$client = new Shopify\\Api($params);\n$helper = $client-\u003egetOAuthHelper();\n\n$token = $helper-\u003egetAccessToken($code);\necho $token-\u003eaccess_token;\necho $token-\u003escopes;\n```\n\nBy default, this uses simple session storage. You can implement a custom class that implements `PersistentStorageInterface`,\npass that to `new Shopify\\Api()`, and `OAuthHelper` will use that instead. This will be required if authorization requests and\nredirects may be directed to different servers.\n\n### Using objects\n\nObject properties can be accessed using `object-\u003eproperty`. Nested objects are instantiated classes. All timestamp fields are instances of `\\DateTime`.\n\n```php\nuse Shopify\\Enum\\Fields\\ProductFields;\nuse Shopify\\Enum\\Fields\\ProductVariantFields;\n\n$product = $service-\u003eget($productId);\necho $product-\u003ecreated_at-\u003eformat('Y-m-d H:i:s');\necho $product-\u003etitle;\n\nforeach ($product-\u003evariants as $variant) {\n    echo $variant-\u003eoption1;\n    echo $variant-\u003eoption2;\n}\n```\n\n## References\n\n[Shopify Partner Login](https://partners.shopify.com)\n\n[Shopify API Reference](https://help.shopify.com/api/reference)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobwittman%2Fshopify-php-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobwittman%2Fshopify-php-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobwittman%2Fshopify-php-sdk/lists"}