An object-oriented approach towards using the Shopify API.
Please note: the old version (v0.9) using Guzzle 3.9 is maintained here
- Asset
- Customer
- Dispute
- Fulfillment
- FulfillmentService
- Image
- Metafield
- Order
- Product
- Risk
- Shop
- Theme
- Variant
- Webhook
$ composer require dan/shopify v2.*
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.
This won't always work as not every endpoint supports metafields, and any endpoint that doesn't support metafields will result in a 404
.
Below are examples of all the endpoints that support metafields.
// 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);
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:
$api = Dan\Shopify\Shopify::make($shop, $token);
// Get Shop data
$api->shop() // Returns associative array of shop data
// 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]);
// Assumes setup of client with access token.
$api = Dan\Shopify\Shopify::make($shop, $token);
// Get Shop data
$api->shop() // Returns associative array of shop data
$api->orders->find($order_id = 123); // returns Dan\Shopify/Models/Order
// Alternatively, we may call methods on the API object.
$api->orders->get([], $order_id = 123); // returns array
See Facade usages for other methods available.
In your config/app.php
Dan\Shopify\Integrations\Laravel\ShopifyServiceProvider::class,
'Shopify' => Dan\Shopify\Integrations\Laravel\ShopifyFacade::class,
SHOPIFY_DOMAIN=your-shop-name.myshopify.com
SHOPIFY_TOKEN=your-token-here
Empty or admin
defaults to oldest legacy, learn more
SHOPIFY_API_BASE="admin/api/2019-10"
It will be instantiated with your shop and token you setup in
config/shopify.php
or
Shopify::getAppInstallResponse(
'your_app_client_id',
'your_app_client_secret',
'shop_from_request',
'code_from_request'
);
// returns (object) ['access_token' => '...', 'scopes' => '...']
Dan\Shopify\Util::validAppHmac(
'hmac_from_request',
'your_app_client_secret',
['shop' => '...', 'timestamp' => '...', ...]
);
Dan\Shopify\Util::validWebhookHmac(
'hmac_from_request',
'your_app_client_secret',
file_get_contents('php://input')
);
- Artisan Command to create token
MIT.