PHPackages                             mfdmc/shopify - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. mfdmc/shopify

ActiveLibrary[API Development](/categories/api)

mfdmc/shopify
=============

Shopify PHP SDK to interact with the Shopify API (cloned from donutdan4114/shopify).

097PHP

Since Nov 20Pushed 7y ago1 watchersCompare

[ Source](https://github.com/mfdmc/shopify)[ Packagist](https://packagist.org/packages/mfdmc/shopify)[ RSS](/packages/mfdmc-shopify/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Shopify PHP SDK
===============

[](#shopify-php-sdk)

A simple Shopify PHP SDK for private apps to easily interact with the Shopify API.
[![Travis Build Status](https://camo.githubusercontent.com/c4fe17a511141d55ebc5bc321da9e7a0ed8429949688d2805965fe67d495ec4a/68747470733a2f2f7472617669732d63692e6f72672f646f6e757464616e343131342f73686f706966792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/donutdan4114/shopify)

[Shopify API Documentation](https://docs.shopify.com/api) | [Packagist](https://packagist.org/packages/donutdan4114/shopify) | [Build Status](https://travis-ci.org/donutdan4114/shopify)

Features include:

- ability to easily GET, PUT, POST and DELETE resources
- process and validate incoming webhooks
- automatic rate limiting to avoid API calls from erroring

Setup/Installation
------------------

[](#setupinstallation)

Uses [guzzlehttp/guzzle](https://packagist.org/packages/guzzlehttp/guzzle). You can include this library by running:
`composer require donutdan4114/shopify@dev`

Private &amp; Public Apps
-------------------------

[](#private--public-apps)

You can use this library for private or public app creation. Using private apps is easier because their is no `access_token` required. However, if you want to create a publicly accessible app, you must use the Public App system.

### Private App

[](#private-app)

Simply instantiate a private app with the `shop_domain`, `api_key`, `password`, and `shared_secret`.

```
$client = new Shopify\PrivateApp($SHOPIFY_SHOP_DOMAIN, $SHOPIFY_API_KEY, $SHOPIFY_PASSWORD, $SHOPIFY_SHARED_SECRET);
$result = $client->get('shop');
```

### Public App

[](#public-app)

You must first setup a public app. [View documentation](https://docs.shopify.com/api/introduction/getting-started). You need an authorization URL.

```
session_start();
$client = new Shopify\PublicApp($_GET['shop'], $APP_API_KEY, $APP_SECRET);

// You set a random state that you will confirm later.
$random_state = 'client-id:' . $_SESSION['client_id'];

$client->authorizeUser('[MY_DOMAIN]/redirect.php', [
  'read_products',
  'write_products',
], $random_state);
```

At this point, the user is taken to their store to authorize the application to use their information.
If the user accepts, they are taken to the redirect URL.

```
session_start();
$client = new Shopify\PublicApp($_GET['shop'], $APP_API_KEY, $APP_SECRET);

// Used to check request data is valid.
$client->setState('client-id:' . $_SESSION['client_id']);

if ($token = $client->getAccessToken()) {
  $_SESSION['shopify_access_token'] = $token;
  $_SESSION['shopify_shop_domain'] = $_GET['shop'];
  header("Location: dashboard.php");
}
else {
  die('invalid token');
}
```

It's at this point, in **dashboard.php** you could starting doing API request by setting the `access_token`.

```
session_start();
$client = new Shopify\PublicApp($_SESSION['shopify_shop_domain'], $APP_API_KEY, $APP_SECRET);
$client->setAccessToken($_SESSION['shopify_access_token']);
$products = $client->getProducts();
```

---

Methods
-------

[](#methods)

### GET

[](#get)

Get resource information from the API.

```
$client = new Shopify\PrivateApp($SHOPIFY_SHOP_DOMAIN, $SHOPIFY_API_KEY, $SHOPIFY_PASSWORD, $SHOPIFY_SHARED_SECRET);
$result = $client->get('shop');
```

`$result` is a JSON decoded `stdClass`:

```
object(stdClass)#33 (1) {
  ["shop"]=>
  object(stdClass)#31 (44) {
    ["id"]=>
    int([YOUR_SHOP_ID])
    ["name"]=>
    string(15) "[YOUR_SHOP_NAME]"
    ["email"]=>
    string(22) "[YOUR_SHOP_EMAIL]"
    ["domain"]=>
    string(29) "[YOUR_SHOP_DOMAIN]"
    ...
  }
}

```

Get product IDs by passing query params:

```
$result = $client->get('products', ['query' => ['fields' => 'id']]);
foreach($result->products as $product) {
  print $product->id;
}
```

### POST

[](#post)

Create new content with a POST request.

```
$data = ['product' => ['title' => 'my new product']];
$result = $client->post('products', $data);
```

### PUT

[](#put)

Update existing content with a given ID.

```
$data = ['product' => ['title' => 'updated product name']];
$result = $client->put('products/' . $product_id, $data);
```

### DELETE

[](#delete)

Easily delete resources with a given ID.

```
$client->delete('products/' . $product_id);
```

Simple Wrapper
--------------

[](#simple-wrapper)

To make it easier to work with common API resources, there are several short-hand functions.

```
// Get shop info.
$shop_info = $client->getShopInfo();

// Get a specific product.
$product = $client->getProduct($product_id);

// Delete a specific product.
$client->deleteProduct($product_id);

// Create a product.
$product = $client->createProduct(['title' => 'my new product']);

// Count products easily.
$count = $client->getProductsCount(['updated_at_min' => time() - 3600]);

// Easily get all products without having to worry about page limits.
$products = $client->getProducts();
// This will fetch all products and will make multiple requests if necessary.
// You can easily supply filter arguments.
$products = $client->getProducts(['query' => ['vendor' => 'MY_VENDOR']]);

// For ease-of-use, you should use the getResources() method to automatically handle Shopify's pagination.
$orders = $client->getResources('orders', ['query' => ['fields' => 'id,billing_address,customer']]);
// This will ensure that if there are over 250 orders, you get them all returned to you.

// If efficiency and memory limits are a concern,  you can loop over results manually.
foreach ($this->client->getResourcePager('products', 25) as $product) {
  // Fetches 25 products at a time.
  // If you have 500 products, this will create 20 separate requests for you.
  // PHP memory will only be storing 25 products at a time, which keeps thing memory-efficient.
}
```

Parsing Incoming Webhooks
-------------------------

[](#parsing-incoming-webhooks)

If you have a route setup on your site to accept incoming Shopify webhooks, you can easily parse the data and validate the contents. There are two ways to validate webhooks: manually, or using the client.

```
// Process webhook manually.
$webhook = new Shopify\IncomingWebhook($SHOPIFY_SHARED_SECRET);
try {
  $webhook->validate();
  $data = $webhook->getData();
} catch (Shopify\WebhookException $e) {
  // Errors means you should not process the webhook data.
  error_log($e->getMessage());
}

// Process webhook using the $client.
try {
  $data = $client->getIncomingWebhook($validate = TRUE);
} catch (Shopify\ClientException $e) {
  error_log($e->getMessage());
}
if (!empty($data)) {
  // Do something with the webhook data.
}
```

Error Handling
--------------

[](#error-handling)

Any API error will throw an instance of `Shopify\ClientException`.

```
try {
  $response = $client->put('products/BAD_ID');
} catch (Shopify\ClientException $e) {
  // Get request errors.
  error_log($e->getErrors());
  // Get last response object.
  $last_response = $e->getLastResponse();
  $code = $e->getCode();
  $code = $last_response->getStatusCode();
}
```

API Limit Handling
------------------

[](#api-limit-handling)

This class can handle API rate limiting for you based on Shopify's "leaky bucket" algorithm.
It will automatically slow down requests to not hit the rate limiter.
You can disabled this with:

```
$client->rate_limit = FALSE;
```

You can put in your own rate limiting logic using the `$client->getCallLimit()` and `$client->callLimitReached()` methods.

Testing
-------

[](#testing)

Tests can be run with `phpunit`.
Since the tests actually modify the connected store, you must explicitly allow tests to be run by settings `SHOPIFY_ALLOW_TESTS` environment variable to `TRUE`.
Without that, you will be get a message like:

```
Shopify tests cannot be run.
Running Shopify tests will delete all connected store info.
Set environment variable SHOPIFY_ALLOW_TESTS=TRUE to allow tests to be run.

```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4e032bd4a0fdbe92b6a4a859f16adda941d5e085088b85ce290772c15b987a9c?d=identicon)[mfdmc](/maintainers/mfdmc)

---

Top Contributors

[![donutdan4114](https://avatars.githubusercontent.com/u/1627929?v=4)](https://github.com/donutdan4114 "donutdan4114 (3 commits)")[![mfdmc](https://avatars.githubusercontent.com/u/13784583?v=4)](https://github.com/mfdmc "mfdmc (3 commits)")[![str](https://avatars.githubusercontent.com/u/123817?v=4)](https://github.com/str "str (1 commits)")

### Embed Badge

![Health badge](/badges/mfdmc-shopify/health.svg)

```
[![Health](https://phpackages.com/badges/mfdmc-shopify/health.svg)](https://phpackages.com/packages/mfdmc-shopify)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
