nickywoolf / shopify
There is no license information available for the latest version (1.1.0) of this package.
Another simple Shopify API client
1.1.0
2017-10-30 13:18 UTC
Requires
- kitetail/zttp: ^0.3.0
Requires (Dev)
- phpunit/phpunit: ^6.2
This package is not auto-updated.
Last update: 2024-04-28 01:08:53 UTC
README
Redirect the user to Shopify to get permission to access their shop's data.
$shopify = new NickyWoolf\Shopify\Shopify('example.myshopify.com'); $authorizeUrl = $shopify->authorize('client_id', 'scope', 'redirect_uri'); header("Location: {$authorizationUrl}");
After the user allows access Shopify redirects them back to your whitelisted "redirect_uri." You can whitelist urls in the app settings in your partner account.
Perform checks to make sure request came from Shopify. Finally, request an access token for the user.
$request= new NickyWoolf\Shopify\Request('your_client_secret'); if (! $request->verify($_GET)) { // abort! } $shopify = new NickyWoolf\Shopify\Shopify('example.myshopify.com'); $response = $shopify->post('oauth/access_token', [ 'client_id' => 'your_client_id', 'client_secret' => 'your_client_secret', 'code' => $_GET['code'], ]); $response->json();
[ 'access_token' => 'VALID-ACCESS-TOKEN', 'scope' => 'scope', ]
Make authorized requests with a valid access token.
$shopify = new NickyWoolf\Shopify\Shopify('example.myshopify.com', 'VALID-ACCESS-TOKEN'); $product = $shopify->get('products/1234567890.json')->json();
[ 'product' => [ 'id' => 1234567890, 'title' => 'Example Product', ... ], ]
Example of extracting the resource from the response.
$product = $shopify->get('products/1234567890.json')->extract('product');
[ 'id' => 1234567890, 'title' => 'Example Product', ... ]