2017 © Pedro Peláez
 

project shopify

Shopify API with Laravel integrations using latest Guzzle.

image

dan/shopify

Shopify API with Laravel integrations using latest Guzzle.

  • Friday, June 29, 2018
  • by dan
  • Repository
  • 4 Watchers
  • 4 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 20 Versions
  • 71 % Grown

The README.md

Shopify API

A fluent and object-oriented approach for using the Shopify API., (*1)

Supported Objects / Endpoints:

Versions

PHP Package
8 5.0.*
7 4.0.*
YOLO dev-master

Composer

composer require dan/shopify

Basic Usage

The APIs all function alike, here is an example of usage of the products API., (*2)

$api = Dan\Shopify\Shopify::make($shop = 'shop-name.myshopify.com', $token = 'shpua_abc123');

// Shop information
$api->shop(); // array dictionary

// List of products
$api->products->get(); // array of array dictionaries

// Attach query parameters to a get request
$api->products->get(['created_at_min' => '2023-03-25']); // array of array dictionaries

// A specific product
$api->products('123456789')->get(); // array dictionary

// Get all variants for a product
$api->products('123456789')->variants->get(); // array of array dictionaries

// Get a specific variant for a specific product
$s->api2()->products('123456789')->variants('567891234')->get(); // array dictionary

// Append URI string to a get request
$api->orders('123456789')->get([], 'risks'); // array dictionary

// Create a product.
// See https://shopify.dev/docs/api/admin-rest/2023-01/resources/product#post-products
$api->products->post(['title' => 'Simple Test']); // array dictionary

// Update something specific on a product
$api->products('123456789')->put(['title' => 'My title changed.']); // array dictionary

Basic (very basic) GraphQL

The collection and model utilities that are available ->find(...) and ->findMany(...) for RESTful endpoints are NOT available for GraphQL., (*3)

Some endpoints are only available through Shopify's GraphQL library. This makes me sad because GraphQL is not as readable or intuitive as RESTful APIs, less people understand it, and it's harder to train people on. That said, if you want to jam out with your graphql, there is a client method to assist you., (*4)

For example, fetch delivery profiles (only available in GraphQL)., (*5)

Note: You can safely use the graphql(...) helper method without any concern of changing the state on the Dan\Shopify\Shopify::class., (*6)

$query = "{
  deliveryProfiles (first: 3) {
    edges {
      node {
        id,
        name,
      }
    }
  }
}"

$api->graphql($query); // hipster

Using cursors

Shopify doesn't jam with regular old pagination, sigh ..., (*7)

As of the 2019-10 API version, Shopify has removed per page pagination on their busiest endpoints.
With the deprecation of the per page pagination comes a new cursor based pagination.
You can use the next method to get paged responses.
Example usage:, (*8)

// First call to next can have all the usual query params you might want.
$api->orders->next(['limit' => 100, 'status' => 'closed');

// Further calls will have all query params preset except for limit.
$api->orders->next(['limit' => 100]);

Metafields!

There are multiple endpoints in the Shopify API that have support for metafields.
In effort to support them all, this API has been updated to allow chaining ->metafields from any endpoint., (*9)

This won't always work as not every endpoint supports metafields, and any endpoint that doesn't support metafields will result in a 404., (*10)

Below are examples of all the endpoints that support metafields., (*11)

// Get our API
$api = Dan\Shopify\Shopify::make($shop, $token);

// Store metafields
$api->metafields->get();

// Metafields on an Order
$api->orders($order_id)->metafields->get();

// Metafields on a Product
$api->products($product_id)->metafields->get();

// Metafields on a Variant
$api->products($product_id)->variants($variant_id)->metafields->get();

// Metafields on a Customer
$api->customers($customer_id)->metafields->get();

// Metafields can also be updated like all other endpoints
$api->products($product_id)->metafields($metafield_id)->put($data);

Usage with Laravel

Single Store App

In your config/app.php, (*12)

Add the following to your providers array:

Requires for private app (env token) for single store usage of oauth (multiple stores), (*13)

Dan\Shopify\Integrations\Laravel\ShopifyServiceProvider::class,

Add the following to your aliases array:

If your app only interacts with a single store, there is a Facade that may come in handy., (*14)

'Shopify' => Dan\Shopify\Integrations\Laravel\ShopifyFacade::class,

For facade usage, replace the following variables in your .env

SHOPIFY_DOMAIN=your-shop-name.myshopify.com
SHOPIFY_TOKEN=your-token-here

Optionally replace following variables in your .env

Empty or admin defaults to oldest supported API, learn more, (*15)

SHOPIFY_API_BASE="admin/api/2022-07"

Using the Facade gives you Dan\Shopify\Shopify

It will be instantiated with your shop and token you set up in config/shopify.php, (*16)

Review the Basic Usage above, using the Facade is more or less the same, except you're only interacting with the one store in your config., (*17)

// Facade same as $api->shop(), but for just the one store.
Shopify::shop();

// Facade same as $api->products->get(), but for just the one store.
Shopify::products()->get();

// Facade same as $api->products('123456789')->get(), but for just the one store.
Shopify::products('123456789')->get();

Oauth Apps

Making a public app using oauth, follow the Shopify docs to make your auth url, and use the following helper to retrieve your access token using the code from your callback., (*18)

Get a token for a redirect response.

Shopify::getAppInstallResponse(
    'your_app_client_id', 
    'your_app_client_secret',
    'shop_from_request',
    'code_from_request'
);

// returns (object) ['access_token' => '...', 'scopes' => '...']

Verify App Hmac (works for callback or redirect)

Dan\Shopify\Util::validAppHmac(
    'hmac_from_request', 
    'your_app_client_secret', 
    ['shop' => '...', 'timestamp' => '...', ...]
);

Verify App Webhook Hmac

Dan\Shopify\Util::validWebhookHmac(
    'hmac_from_request', 
    'your_app_client_secret', 
    file_get_contents('php://input')
);

Contributors

Todo

  • Artisan Command to create token

License

MIT., (*19)

The Versions

29/06 2018

dev-master

9999999-dev

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

29/06 2018

v2.1.5

2.1.5.0

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

08/03 2018

v2.1.4

2.1.4.0

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

08/03 2018

v2.1.3

2.1.3.0

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

08/03 2018

v2.1.2

2.1.2.0

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

07/03 2018

v2.1.1

2.1.1.0

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

07/03 2018

v2.1.0

2.1.0.0

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

02/03 2018

v2.0.0

2.0.0.0

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

23/01 2018

v1.0.0.11

1.0.0.11

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

09/01 2018

v1.0.0.10

1.0.0.10

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

05/01 2018

v1.0.0.9

1.0.0.9

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

29/12 2017

v1.0.0.8

1.0.0.8

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

27/12 2017

v1.0.0.7

1.0.0.7

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

30/10 2017

v1.0.0.6

1.0.0.6

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

30/10 2017

v1.0.0.5

1.0.0.5

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

01/08 2017

v1.0.0.4

1.0.0.4

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

26/07 2017

v1.0.0.3

1.0.0.3

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

25/07 2017

v1.0.0.2

1.0.0.2

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

20/07 2017

v1.0.0.1

1.0.0.1

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks

19/07 2017

v1.0.0.0

1.0.0.0

Shopify API with Laravel integrations using latest Guzzle.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api shopify webhooks