PHPackages                             mtownsend/snipcart-api - 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. mtownsend/snipcart-api

ActiveLibrary[API Development](/categories/api)

mtownsend/snipcart-api
======================

A PHP (and Laravel) package to interface with the Snipcart api.

1.1.0(5y ago)11496MITPHPPHP ~7.0|~8.0CI failing

Since May 14Pushed 5y ago1 watchersCompare

[ Source](https://github.com/mtownsend5512/snipcart-api)[ Packagist](https://packagist.org/packages/mtownsend/snipcart-api)[ RSS](/packages/mtownsend-snipcart-api/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

 The easiest and fastest way to get up and running with Snipcart's api.

[![Snipcart API - mtownsend/snipcart-api](https://camo.githubusercontent.com/c4db5524e015c1e925d9f484a1301d6eec212d29e878cbb2d2ac47f3707c43a9/68747470733a2f2f692e696d6775722e636f6d2f46674c444f61612e706e67 "Snipcart API - mtownsend/snipcart-api")](https://camo.githubusercontent.com/c4db5524e015c1e925d9f484a1301d6eec212d29e878cbb2d2ac47f3707c43a9/68747470733a2f2f692e696d6775722e636f6d2f46674c444f61612e706e67)

First steps
-----------

[](#first-steps)

- [Register an account and obtain your api key](https://app.snipcart.com/register)
- [Snipcart Developer Documentation](https://docs.snipcart.com/api-reference/introduction)

Installation
------------

[](#installation)

Install via composer:

```
composer require mtownsend/snipcart-api

```

*This package can be used with any PHP 7.0+ application but has special support for Laravel.*

### Registering the service provider (Laravel users)

[](#registering-the-service-provider-laravel-users)

For Laravel 5.4 and lower, add the following line to your `config/app.php`:

```
/*
 * Package Service Providers...
 */
Mtownsend\SnipcartApi\Providers\SnipcartApiServiceProvider::class,
```

For Laravel 5.5 and greater, the package will auto register the provider for you.

### Using Lumen

[](#using-lumen)

To register the service provider, add the following line to `app/bootstrap/app.php`:

```
$app->register(Mtownsend\SnipcartApi\Providers\SnipcartApiServiceProvider::class);
```

### Publishing the config file (Laravel users)

[](#publishing-the-config-file-laravel-users)

```
php artisan vendor:publish --provider="Mtownsend\SnipcartApi\Providers\SnipcartApiServiceProvider"

```

Once your `snipcart.php` has been published your to your config folder, add the api key you obtained from [Snipcart](https://app.snipcart.com/dashboard/account/credentials). If you are using Laravel and put your Snipcart api key in the config file, Laravel will automatically set your api key every time you instantiate the class through the helper or facade.

Quick start
-----------

[](#quick-start)

### Using the class

[](#using-the-class)

```
use Mtownsend\SnipcartApi\SnipcartApi;

$orders = (new SnipcartApi($apiKey))->get()->from('/orders')->send();
```

### HTTP methods

[](#http-methods)

This package supports RESTful HTTP methods including `GET` (default), `POST`, `PUT`, `PATCH` and `DELETE`.

#### GET example

[](#get-example)

```
// Get a list of orders with a query string of ?limit=10&offset=5&status=Processed
$orders = (new SnipcartApi($apiKey))->get()->from('/orders')->payload([
	'limit' => 10,
	'offset' => 5,
	'status' => 'Processed'
])->send();
```

#### POST example

[](#post-example)

```
// Post a refund
$refund = (new SnipcartApi($apiKey))->post()->payload([
	'token' => '6dc8e374-7e30-4dc5-9b68-2d605819e7f0',
	'amount' => 5.00,
	'comment' => "We're refunding $5 for your order."
])->to('/orders/6dc8e374-7e30-4dc5-9b68-2d605819e7f0/refunds')->send();
```

#### PUT example

[](#put-example)

```
// Update a product
$product = (new SnipcartApi($apiKey))->put()->payload([
	'stock' => 200,
	'allowOutOfStockPurchases' => false
])->to('/products/3932ecd1-6508-4209-a7c6-8da4cc75590d')->send();
```

#### DELETE example

[](#delete-example)

```
// Delete an allowed domain from your Snipcart account
$domain = (new SnipcartApi($apiKey))->delete()->payload([
	[
		[
			'domain' => 'subdomain.my-website.com',
			'protocol' => 'https'
		],
	]
])->from('/settings/alloweddomains')->send();
```

### Class methods

[](#class-methods)

#### -&gt;to(string '/url') or -&gt;from(string '/url')

[](#-tostring-url-or--fromstring-url)

The `to` or `from` methods are identical and only exist to make your syntax make more semantic sense (`get()->from()` or `post()->to()`). These methods expect to receive a relative url path for the Snipcart endpoint you're attempting to communicate with. For example, if you want to get a list of orders from `https://app.snipcart.com/api/orders`, you would utilize your method of choice and pass it an argument of `/orders`.

Note: It does not matter if you prepend a slash, append a slash, both, or exclude both. The package gracefully handles your usage of prepended/appended slashes of the relative url. Any of these examples would be acceptable arguments: `/orders/`, `/orders`, `orders/`, or `orders`.

#### -&gt;payload(array \['key' =&gt; 'value'\]) or -&gt;payload('key', 'value')

[](#-payloadarray-key--value-or--payloadkey-value)

The `payload` method allows you to pass data through with your request.

If the request is a `GET` operation the payload will be converted to a valid query string. E.g. `['from' => '2018-05-05', 'to' => '2019-05-05']` will produce `?from=2018-05-05&to=2019-05-05` and be automatically appended to your request url.

Alternatively, if your preference is to manually include your query string for `GET` requests you may omit the `payload` method entirely and append your query string to the `to`/`from` method. E.g. `->get()->from('/orders?limit=10&offset=5')->send()`.

If the request is a `POST`, `PUT`, `PATCH` or `DELETE` operation the payload will automatically be converted to json and sent in the request's body.

#### -&gt;send()

[](#-send)

The `send` method triggers the api call to be sent and returns the response.

#### -&gt;addHeader(string 'key', string 'value')

[](#-addheaderstring-key-string-value)

The `addHeader` method accepts two arguments. The first is the header key and the second is the header value. By default this package sets the `Accept` and `Content-Type` for you.

#### -&gt;addHeaders(array \['key' =&gt; 'value'\])

[](#-addheadersarray-key--value)

The `addHeaders` method accepts an associative array of key/values to set as headers for the api request.

#### -&gt;responseCode()

[](#-responsecode)

The `responseCode` method returns the http code received from the server for the request. Note: this method should only be used if you are breaking up your api call into multiple variables.

#### -&gt;successful()

[](#-successful)

The `successful` method parses the http code received from the server and checks for any 2XX code and returns a boolean. Note: this method should only be used if you are breaking up your api call into multiple variables.

### Checking for failed api calls

[](#checking-for-failed-api-calls)

Snipcart's api provides graceful failure in many circumstances. If you were to make an api call to the endpoint `/does-not-exist`, the response would be `null`. You could easily check the value of your request object with a simple `if` statement before attempting to perform any logic.

```
$response = (new SnipcartApi($apiKey))->get()->from('/does-not-exist')->send();
if (!$response) {
	// api call failed
}
// else: do something with the response data...
```

Alternatively, if you prefer to split up your api call into multiple variables, the `SnipcartApi` class comes with a `successful` method.

```
$call = (new SnipcartApi($apiKey))->get()->from('/does-not-exist');
$response = $call->send();
if (!$call->successful()) {
	// api call failed
}
// else: do something with the response data...
```

### Using the global helper (Laravel users)

[](#using-the-global-helper-laravel-users)

If you are using Laravel, this package provides a convenient helper function which is globally accessible. The package will automatically set your api key from your `config/snipcart.php` file.

```
snipcart()->get()->from('/orders')->send();
```

### Using the facade (Laravel users)

[](#using-the-facade-laravel-users)

If you are using Laravel, this package provides a facade. To register the facade add the following line to your `config/app.php` under the `aliases` key. The package will automatically set your api key from your `config/snipcart.php` file.

```
'Snipcart' => Mtownsend\SnipcartApi\Facades\SnipcartApi::class,
```

```
use Snipcart;

Snipcart::get()->from('/orders')->send();
```

Credits
-------

[](#credits)

- Mark Townsend
- [All Contributors](../../contributors)

Testing
-------

[](#testing)

*Tests coming soon...*

You can run the tests with:

```
./vendor/bin/phpunit
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~645 days

Total

2

Last Release

1910d ago

PHP version history (2 changes)1.0.0PHP ~7.0

1.1.0PHP ~7.0|~8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f66b358807122df39b73f83e44d42f5a420d120986343b78a868f51c8c64eb49?d=identicon)[mtownsend](/maintainers/mtownsend)

---

Top Contributors

[![mtownsend5512](https://avatars.githubusercontent.com/u/4945553?v=4)](https://github.com/mtownsend5512 "mtownsend5512 (9 commits)")

---

Tags

apicartecommercesnipsnipcartapilaravelsubscriptionsrefundsecommerceorderscartproductsshippingabandonedcustomerssnipcartsnip

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mtownsend-snipcart-api/health.svg)

```
[![Health](https://phpackages.com/badges/mtownsend-snipcart-api/health.svg)](https://phpackages.com/packages/mtownsend-snipcart-api)
```

###  Alternatives

[mollie/laravel-mollie

Mollie API client wrapper for Laravel &amp; Mollie Connect provider for Laravel Socialite

3624.1M28](/packages/mollie-laravel-mollie)[aimeos/aimeos-laravel

Cloud native, API first Laravel eCommerce package with integrated AI for ultra-fast online shops, marketplaces and complex B2B projects

8.6k214.7k3](/packages/aimeos-aimeos-laravel)[aimeos/aimeos-headless

Aimeos headless ecommerce system

2.5k2.3k](/packages/aimeos-aimeos-headless)[siro/php-klaviyo-api

Low level but elegant Klaviyo full API wrapper for PHP with asynchronous track event support

16115.4k](/packages/siro-php-klaviyo-api)

PHPackages © 2026

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