PHPackages                             rocket-code/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. rocket-code/shopify

ActiveLibrary[API Development](/categories/api)

rocket-code/shopify
===================

2.0.2(10y ago)92119.8k↓33.3%47[14 issues](https://github.com/joshrps/laravel-shopify-API-wrapper/issues)[2 PRs](https://github.com/joshrps/laravel-shopify-API-wrapper/pulls)2PHP

Since Dec 1Pushed 5y ago6 watchersCompare

[ Source](https://github.com/joshrps/laravel-shopify-API-wrapper)[ Packagist](https://packagist.org/packages/rocket-code/shopify)[ RSS](/packages/rocket-code-shopify/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (13)Used By (2)

Laravel / Shopify API Wrapper
=============================

[](#laravel--shopify-api-wrapper)

An easy-to-use PHP package to communicate with [Shopify's API](http://docs.shopify.com/api) in Laravel.

\##Installation ####Require rocket-code/shopify in `composer.json`

Add `"rocket-code/shopify"` in your "require" object. With a blank Laravel install, it will look something like this:

For Laravel 5, use `"rocket-code/shopify": "~2.0"`. For Laravel 4, use `"rocket-code/shopify": "~1.0"`.

```
	"require": {
		"laravel/framework": "4.2.*",
		"rocket-code/shopify": "~1.0"
	}

```

\####Add the Service Provider In `app/config/app.php`, add `RocketCode\Shopify\ShopifyServiceProvider` to the end of the `providers` array.

\##Setting Up To begin, use `App::make()` to grab an instance of the `API` class.

```
$sh = App::make('ShopifyAPI');

```

\####Loading API Credentials Simply pass an array with the following keys (and filled-in values) to prepare. Not all values need to be passed at once; you can call the `setup()` method as many times as you'd like; it will only accept the following 4 keys, and overwrite a values if it's already set.

```
$sh->setup(['API_KEY' => '', 'API_SECRET' => '', 'SHOP_DOMAIN' => '', 'ACCESS_TOKEN' => '']);

```

\#####Shortcut: Pass the setup array as the second argument in `App::make()`:

```
$sh = App::make('ShopifyAPI', ['API_KEY' => '', 'API_SECRET' => '', 'SHOP_DOMAIN' => '', 'ACCESS_TOKEN' => '']);

```

That's it! You're ready to make some API calls.

\##Finding the Install URL After setting up with at least `SHOP_DOMAIN` &amp; `API_KEY`, call `installURL()` with an array of permissions ([the app's Scope](docs.shopify.com/api/authentication/oauth#scopes)):

```
$sh->installURL(['permissions' => array('write_orders', 'write_products')]);

```

You may also pass a redirect URL per the `redirect_uri` parameter [as described by the Shopify API Docs](http://docs.shopify.com/api/authentication/oauth#asking-for-permission)

```
$sh->installURL(['permissions' => array('write_orders', 'write_products'), 'redirect' => 'http://myapp.com/success']);

```

\##Authentication / Getting OAuth Access Token In order to make Authenticated requests, [the Access Token must be passed as a header in each request](http://docs.shopify.com/api/authentication/oauth#making-authenticated-requests). This package will automatically do that for you, but you must first authenticate your app on each store (as the user installs it), and save the Access Token.

Once the user accesses the Install URL and clicks the Install button, they will be redirected back to your app with data in the Query String.

After setting up with at least `SHOP_DOMAIN`, `API_KEY`, &amp; `API_SECRET`, call `getAccessToken()` with the code passed back in the URL. Laravel makes this easy:

```
$code = Input::get('code');
$sh = App::make('ShopifyAPI', ['API_KEY' => '', 'API_SECRET' => '', 'SHOP_DOMAIN' => '']);

try
{
	$accessToken = $sh->getAccessToken($code);
}
catch (Exception $e)
{
	echo 'Error: ' . $e->getMessage() . '';
}

// Save $accessToken

```

\####Verifying OAuth Data Shopify returns a hashed value to validate the data against. To validate (recommended before calling `getAccessToken()`), utilize `verifyRequest()`.

```
try
{
	$verify = $sh->verifyRequest(Input::all());
	if ($verify)
	{
		$code = Input::get('code');
		$accessToken = $sh->getAccessToken($code);
	}
	else
	{
		// Issue with data
	}

}
catch (Exception $e)
{
	echo 'Error: ' . $e->getMessage() . '';
}

```

`verifyRequest()` returns `TRUE` when data is valid, otherwise `FALSE`. It throws an Exception in two cases: If the timestamp generated by Shopify and your server are more than an hour apart, or if the argument passed is not an array or URL-encoded string of key/values.

If you would like to skip the timestamp check (not recommended unless you cannot correct your server's time), you can pass `TRUE` as a second argument to `verifyRequest()` and timestamps will be ignored:

```
$verify = $sh->verifyRequest(Input::all(), TRUE);

```

Private Apps
------------

[](#private-apps)

The API Wrapper does not distinguish between private and public apps. In order to utilize it with a private app, set up everything as you normally would, replacing the OAuth Access Token with the private app's Password.

\##Calling the API Once set up, simply pass the data you need to the `call()` method.

```
$result = $sh->call($args);

```

\####`call()` Parameters The parameters listed below allow you to set required values for an API call as well as override additional default values.

- `METHOD`: The HTTP method to use for your API call. Different endpoints require different methods.
    - Default: `GET`
- `URL`: The URL of the API Endpoint to call.
    - Default: `/` (not an actual endpoint)
- `HEADERS`: An array of additional Headers to be sent
    - Default: Empty `array()`. Headers that are automatically sent include:
        - Accept
        - Content-Type
        - charset
        - X-Shopify-Access-Token
- `CHARSET`: Change the charset if necessary
    - Default: `UTF-8`
- `DATA`: An array of data being sent with the call. For example, `$args['DATA'] = array('product' => $product);` For an [`/admin/products.json`](http://docs.shopify.com/api/product#create) product creation `POST`.
    - Default: Empty `array()`
- `RETURNARRAY`: Set this to `TRUE` to return data in `array()` format. `FALSE` will return a `stdClass` object.
    - Default: `FALSE`
- `ALLDATA`: Set this to `TRUE` if you would like all error and cURL info returned along with your API data (good for debugging). Data will be available in `$result->_ERROR` and `$result->_INFO`, or `$result['_ERROR']` and `$result['_INFO']`, depending if you are having it returned as an object or array. Recommended to be set to `FALSE` in production.
    - Default: `FALSE`
- `FAILONERROR`: The value passed to cURL's [CURLOPT\_FAILONERROR](http://php.net/manual/en/function.curl-setopt.php) setting. `TRUE` will cause the API Wrapper to throw an Exception if the HTTP code is &gt;= `400`. `FALSE` in combination with `ALLDATA` set to `TRUE` will give you more debug information.
    - Default: `TRUE`

\##Some Examples Assume that `$sh` has already been set up as documented above.

\####Listing Products

```
try
{

	$call = $sh->call(['URL' => 'products.json', 'METHOD' => 'GET', 'DATA' => ['limit' => 5, 'published_status' => 'any']]);
}
catch (Exception $e)
{
	$call = $e->getMessage();
}

echo '';
var_dump($call);
echo '';

```

`$call` will either contain a `stdClass` object with `products` or an Exception error message.

\####Creating a snippet from a Laravel View

```
$testData = ['name' => 'Foo', 'location' => 'Bar'];
$view = (string) View::make('snippet', $testData);

$themeID = 12345678;

try
{
	$call = $sh->call(['URL' => '/admin/themes/' . $themeID . '/assets.json', 'METHOD' => 'PUT', 'DATA' => ['asset' => ['key' => 'snippets/test.liquid', 'value' => $view] ] ]);
}
catch (Exception $e)
{
	$call = $e->getMessage();
}

echo '';
var_dump($call);
echo '';

```

\####Performing operations on multiple shops The `setup()` method makes changing the current shop simple.

```
$apiKey = '123';
$apiSecret = '456';

$sh = App::make('ShopifyAPI', ['API_KEY' => $apiKey, 'API_SECRET' => $apiSecret]);

$shops = array(
		'my-shop.myshopify.com'		=> 'abc',
		'your-shop.myshopify.com'	=> 'def',
		'another.myshopify.com'		=> 'ghi'
		);

foreach($shops as $domain => $access)
{
	$sh->setup(['SHOP_DOMAIN' => $domain, 'ACCESS_TOKEN'' => $access]);
	// $sh->call(), etc

}

```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 93.8% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~38 days

Total

11

Last Release

3962d ago

Major Versions

1.0.7 → 2.0.12015-04-02

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4356581?v=4)[Josh Toth](/maintainers/joshrps)[@joshrps](https://github.com/joshrps)

---

Top Contributors

[![joshrps](https://avatars.githubusercontent.com/u/4356581?v=4)](https://github.com/joshrps "joshrps (45 commits)")[![magnetas](https://avatars.githubusercontent.com/u/11045903?v=4)](https://github.com/magnetas "magnetas (3 commits)")

### Embed Badge

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

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[echolabsdev/prism

A powerful Laravel package for integrating Large Language Models (LLMs) into your applications.

2.3k388.3k10](/packages/echolabsdev-prism)[sburina/laravel-whmcs-up

WHMCS API client and user provider for Laravel

271.3k](/packages/sburina-laravel-whmcs-up)

PHPackages © 2026

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