{"id":21825941,"url":"https://github.com/shopifychamp/shopify-api-php-sdk","last_synced_at":"2026-02-28T17:04:15.320Z","repository":{"id":57049811,"uuid":"250869219","full_name":"shopifychamp/shopify-api-php-sdk","owner":"shopifychamp","description":"PHP SDK for Shopify REST and GraphQL API","archived":false,"fork":false,"pushed_at":"2023-09-29T09:48:07.000Z","size":876,"stargazers_count":7,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T05:37:20.492Z","etag":null,"topics":["php-sdk","php-shopify","shopify","shopify-graphql-api","shopify-php","shopify-sdk"],"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/shopifychamp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2020-03-28T18:46:06.000Z","updated_at":"2025-03-14T06:02:38.000Z","dependencies_parsed_at":"2024-11-25T15:56:45.672Z","dependency_job_id":null,"html_url":"https://github.com/shopifychamp/shopify-api-php-sdk","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/shopifychamp/shopify-api-php-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopifychamp%2Fshopify-api-php-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopifychamp%2Fshopify-api-php-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopifychamp%2Fshopify-api-php-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopifychamp%2Fshopify-api-php-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shopifychamp","download_url":"https://codeload.github.com/shopifychamp/shopify-api-php-sdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shopifychamp%2Fshopify-api-php-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29943688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T13:49:17.081Z","status":"ssl_error","status_checked_at":"2026-02-28T13:48:50.396Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["php-sdk","php-shopify","shopify","shopify-graphql-api","shopify-php","shopify-sdk"],"created_at":"2024-11-27T18:03:03.170Z","updated_at":"2026-02-28T17:04:15.289Z","avatar_url":"https://github.com/shopifychamp.png","language":"PHP","readme":"# SHOPIFY API PHP SDK\n\n[![Latest Stable Version](https://poser.pugx.org/shopifychamp/shopify-api-php-sdk/v/stable)](https://packagist.org/packages/shopifychamp/shopify-api-php-sdk)\n[![License](https://poser.pugx.org/shopifychamp/shopify-api-php-sdk/license)](https://packagist.org/packages/shopifychamp/shopify-api-php-sdk)\n\nPHP SDK helps to connect with shopify [Public App](https://shopify.dev/concepts/apps#public-apps) and [Private App](https://shopify.dev/concepts/apps#private-apps) using [REST Api](https://shopify.dev/docs/admin-api/rest/reference) and [Graphql](https://shopify.dev/docs/admin-api/graphql/reference).\n* Call GET, POST, PUT and DELETE RestApi method.\n* Process GraphQL Admin API for [Query root](https://shopify.dev/docs/admin-api/graphql/reference/queryroot) and [Mutations](https://shopify.dev/docs/admin-api/graphql/reference/mutation).\n* Queryroot is used to get resources and mutations is used to update resources (products/orders/customers). \n* Automatic manage Shopify API rate limits.\n* Compatible with [Cursor Based Pagination](https://shopify.dev/tutorials/make-paginated-requests-to-rest-admin-api) to resource with pagination.\n\n## Installation\n* Install package with Composer\n```\n$ composer require shopifychamp/shopify-api-php-sdk\n```\n## Requirements\n1. For Api call need [Guzzle](https://github.com/guzzle/guzzle). The recommended way to install Guzzle is through [Composer](https://getcomposer.org/).\n    ```\n    $ composer require guzzlehttp/guzzle\n    ```\n2. To prepare graphql query with [GraphQL query builder](https://github.com/rudiedirkx/graphql-query).\n   \n    ```\n    $ composer require rdx/graphql-query\n    ```\n## Getting started\n### Initialize the client\n#### 1.  For Private App\n* To create instance of `Client` class, need `shop`, `api_key`, `password` of private app, `api_params` is an array to pass api version with `YYYY-DD/unstable` format otherwise, Api latest version will be assigned.\n    \n    ```\n    \u003c?php \n    require(__DIR__ . '/../vendor/autoload.php');\n    use Shopify\\PrivateApp;\n    \n    $api_params['version'] = '2019-10';\n    $client = new Shopify\\PrivateApp($shop, $api_key, $password, $api_params);\n    ```\n#### 2. For Public App\n* To create instance of `Client` class, need `shop`, `api_key`, `api_secret_key` of public app.\n    \n    ```    \n    \u003c?php \n    require(__DIR__ . '/../vendor/autoload.php');\n    use Shopify\\PuplicApp;\n    \n    $api_params['version'] = '2019-10';\n    $client = new Shopify\\PublicApp($shop, $api_key, $api_secret_key, $api_params);\n    ```\n* Prepare authorise url to install public app and get `access_token` to store in database or session for future api call.\n    ```\n    if(isset($_GET['code']))\n    {\n        //get access_token after authorization of public app\n        if($access_token = $client-\u003egetAccessToken($_GET)){\n            //set access_token for api call\n            $client-\u003esetAccessToken($access_token);\n            $response = $client-\u003ecall('GET','products',['limit'=\u003e250]);\n        }\n    }else{\n        //$redirect_uri (mention in App URL in your public app)\n        $redirect_url= isset($_SERVER[\"HTTPS\"]) \u0026\u0026 $_SERVER[\"HTTPS\"] == \"on\"?'https://':'http://';\n        if ($_SERVER[\"SERVER_PORT\"] != \"80\") {\n            $redirect_url .= $_SERVER[\"SERVER_NAME\"].\":\".$_SERVER[\"SERVER_PORT\"].$_SERVER[\"REQUEST_URI\"];\n        } else {\n            $redirect_url .= $_SERVER[\"SERVER_NAME\"].$_SERVER[\"REQUEST_URI\"];\n        }\n\n        header('Location: '.urldecode($client-\u003eprepareAuthorizeUrl($redirect_url)));\n    }\n    ```\n### Call REST Api    \n* Get Products with limit 250  with `call()` function\n    ```\n    $response = $client-\u003ecall('GET','products',['limit'=\u003e250]);\n    print_r($response);\n    ```\n* Get products of next page with page_info\n    ```\n    $response = $client-\u003ecall('GET','products',['limit'=\u003e250]);\n    ```\n    \n    Check next page available with `hasNextPage()` function: \n\n    ```\n    if($client-\u003ehasNextPage())\n    {\n        $next_page_response = $client-\u003ecall('GET','products',['limit'=\u003e20,'page_info'=\u003e$client-\u003egetNextPage()]);\n        print_r($next_page_response);\n    }\n    ```\n    \n    Check if previous page available with `hasPrevPage()` function:\n\n    ```\n    if($client-\u003ehasPrevPage())\n    {\n        $prev_page_response = $client-\u003ecall('GET','products',['limit'=\u003e20,'page_info'=\u003e$client-\u003egetPrevPage()]);\n        print_r($prev_page_response);\n    }\n    ```\n    \n### Call GraphQL Api   \n\n* Get product title, description with id by `query()` function\n    \n    ```\n    {\n        product(id: \"gid://shopify/Product/1432379031652\") {\n          title\n          description\n        }\n    }\n    ```\n    Note: \n    * For single attribute and field\n    ``` \n        attribute('id','gid://shopify/Product/1432379031652') and field('title')\n    ```    \n    * For multiple attributes and fields \n    ``` \n    attributes(['product_type','fragrance','limit'=\u003e250]) and `fields(['title','description'])\n    ```\n    Prepare query:\n    \n    ```\n    \u003c?php \n    use rdx\\graphqlquery\\Query;\n    \n    $query = Query::query(\"\");\n    $query-\u003efields('product');\n    $query-\u003eproduct-\u003eattribute('id', \"gid://shopify/Product/1432379031652\");\n    $query-\u003eproduct-\u003efields(['title','description']);\n    $graphqlString = $query-\u003ebuild();\n    \n    ```\n    \n    Call GraphQL with `callGraphql()` function:\n    \n    ```\n    $response = $client-\u003ecallGraphql($graphqlString);\n    ```\n    \n* Create customer with graphql `mutation()` function\n\n    ```\n    mutation {\n      customerCreate(input: { firstName: \"John\", lastName: \"Tate\", email: \"john@johns-apparel.com\" }) {\n        customer {\n          id\n        }\n      }\n    }\n    ```\n    \n    Prepare mutation:\n    \n    ```\n    \u003c?php \n    use rdx\\graphqlquery\\Query;\n    \n    $query = Query::mutation();\n    $query-\u003efields('customerCreate');\n    $query-\u003ecustomerCreate-\u003eattribute('input',['firstName'=\u003e'John','lastName'=\u003e \"Tate\", 'email'=\u003e \"john@johns-apparel.com\"]);\n    $query-\u003ecustomerCreate-\u003efield('customer');\n    $query-\u003ecustomerCreate-\u003ecustomer-\u003efield('id');\n    $graphqlString = $query-\u003ebuild();\n    ```\n    \n    Call GraphQL qith `callGraphql()` function:\n    \n    ```\n    $response = $client-\u003ecallGraphql($graphqlString);\n    ```\n* Cursor Pagination with graphQL\n\n    ```\n    {\n      products(first: 250) {\n        edges {\n          cursor\n          node {\n            id\n          }\n        }\n      }\n    }\n  ```\n    Prepare Query and `$reserve_query` variable to store query for next page call:\n        \n    ```\n    \u003c?php \n    use rdx\\graphqlquery\\Query;\n    \n    $query = Query::query(\"\");\n    $query-\u003efields('products');\n    $query-\u003eproducts-\u003eattribute('first', 250);\n    $query-\u003eproducts-\u003efield('edges');\n    $query-\u003eproducts-\u003eedges-\u003efields(['cursor','node']);\n    $query-\u003eproducts-\u003eedges-\u003enode-\u003efields(['title','description']);\n    $reserve_query = $query;\n    $graphqlString = $query-\u003ebuild();\n  \n    ```\n    Call GraphQL qith `callGraphql()` function. And \n        \n    ```\n    $response = $client-\u003ecallGraphql($graphqlString);\n    \n    ```\n    If you continue repeating this step with the cursor value of the last product in each response you get until your response is empty. So need to check `cursor` index available in last array of `$response` then repeat call by adding cursor value with `after` attribute in products field. \n    \n    ```\n    if(isset($response['data']['products']['edges']) \u0026\u0026 $last_array = end($response['data']['products']['edges']))\n    {\n        if(isset($last_array['cursor']))\n        {\n            //assign cursor value in `last` attribute\n            $query = $reserve_query-\u003eproducts-\u003eattribute('after', $last_array['cursor']);\n            $graphqlString = $reserve_query-\u003ebuild();\n            $next_response = $client-\u003ecallGraphql($graphqlString);\n            print_r($next_response);\n        }\n    }\n    ```\n    \n    \n### Error Handling\n\nBelow errors handled with `ApiException` Class\n* Trying to pass invalid api version\n* Trying to pass invalid shop domain\n* Http REST api call exception from Guzzle(`GuzzleHttp\\Exception\\RequestException`) \n    ```\n    try\n    {\n        $client = new Shopify\\PrivateApp($shop, $api_key, $password, $api_params);\n        $response = $client-\u003ecall('GET','products',['limit'=\u003e20]);\n        print_r($response);\n    }\n    catch (\\Shopify\\Exception\\ApiException $e)\n    {\n        echo \"Errors: \".$e-\u003egetError().'\u003cbr\u003e status code: '.$e-\u003egetCode();\n    }\n    ```\n## References\n* [Shopify API Reference](https://shopify.dev/docs/admin-api/)\n* [GraphQL Query Builder](https://github.com/rudiedirkx/graphql-query)\n* [Guzzle Documentation](http://docs.guzzlephp.org/en/stable/)\n\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshopifychamp%2Fshopify-api-php-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshopifychamp%2Fshopify-api-php-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshopifychamp%2Fshopify-api-php-sdk/lists"}