Giter Site home page Giter Site logo

shopify's Introduction

Shopify API

An object-oriented approach towards using the Shopify API.

Please note: the old version (v0.9) using Guzzle 3.9 is maintained here

Supported Objects / Endpoints:

Composer

$ composer require dan/shopify v2.*

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.
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);

Updated to work with cursors!

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]);

Usage without Laravel

// 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.

Usage with Laravel

Single Store App

In your config/app.php

Add the following to your providers array:

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

Add the following to your aliases array:

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

Replace 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 legacy, learn more

SHOPIFY_API_BASE="admin/api/2019-10"

Using the Facade gives you Dan\Shopify\Shopify

It will be instantiated with your shop and token you setup in config/shopify.php


Examples of saving data.

Creating a product using a model

Updating a product using a model

Add a product to a collection

or


Embedded Apps

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.