{"id":22917441,"url":"https://github.com/mtownsend5512/snipcart-api","last_synced_at":"2025-07-07T22:08:11.577Z","repository":{"id":57021639,"uuid":"186700318","full_name":"mtownsend5512/snipcart-api","owner":"mtownsend5512","description":"A PHP (and Laravel) package to interface with the Snipcart api.","archived":false,"fork":false,"pushed_at":"2021-02-18T19:43:30.000Z","size":10,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-21T20:43:11.901Z","etag":null,"topics":["api","cart","ecommerce","snip","snipcart"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtownsend5512.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-14T21:04:52.000Z","updated_at":"2023-11-05T01:50:06.000Z","dependencies_parsed_at":"2022-08-22T20:30:56.319Z","dependency_job_id":null,"html_url":"https://github.com/mtownsend5512/snipcart-api","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fsnipcart-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fsnipcart-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fsnipcart-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fsnipcart-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtownsend5512","download_url":"https://codeload.github.com/mtownsend5512/snipcart-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229670191,"owners_count":18104836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","cart","ecommerce","snip","snipcart"],"created_at":"2024-12-14T06:17:56.409Z","updated_at":"2024-12-14T06:17:57.079Z","avatar_url":"https://github.com/mtownsend5512.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\tThe easiest and fastest way to get up and running with Snipcart's api.\n\u003c/p\u003e\n\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://i.imgur.com/FgLDOaa.png\" alt=\"Snipcart API - mtownsend/snipcart-api\" title=\"Snipcart API - mtownsend/snipcart-api\"\u003e\n\u003c/p\u003e\n\n## First steps\n\n* [Register an account and obtain your api key](https://app.snipcart.com/register)\n* [Snipcart Developer Documentation](https://docs.snipcart.com/api-reference/introduction)\n\n## Installation\n\nInstall via composer:\n\n```\ncomposer require mtownsend/snipcart-api\n```\n\n*This package can be used with any PHP 7.0+ application but has special support for Laravel.*\n\n### Registering the service provider (Laravel users)\n\nFor Laravel 5.4 and lower, add the following line to your ``config/app.php``:\n\n```php\n/*\n * Package Service Providers...\n */\nMtownsend\\SnipcartApi\\Providers\\SnipcartApiServiceProvider::class,\n```\n\nFor Laravel 5.5 and greater, the package will auto register the provider for you.\n\n### Using Lumen\n\nTo register the service provider, add the following line to ``app/bootstrap/app.php``:\n\n```php\n$app-\u003eregister(Mtownsend\\SnipcartApi\\Providers\\SnipcartApiServiceProvider::class);\n```\n\n### Publishing the config file (Laravel users)\n\n````\nphp artisan vendor:publish --provider=\"Mtownsend\\SnipcartApi\\Providers\\SnipcartApiServiceProvider\"\n````\n\nOnce 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.\n\n## Quick start\n\n### Using the class\n\n```php\nuse Mtownsend\\SnipcartApi\\SnipcartApi;\n\n$orders = (new SnipcartApi($apiKey))-\u003eget()-\u003efrom('/orders')-\u003esend();\n```\n\n### HTTP methods\n\nThis package supports RESTful HTTP methods including ``GET`` (default), ``POST``, ``PUT``, ``PATCH`` and ``DELETE``.\n\n#### GET example\n```php\n// Get a list of orders with a query string of ?limit=10\u0026offset=5\u0026status=Processed\n$orders = (new SnipcartApi($apiKey))-\u003eget()-\u003efrom('/orders')-\u003epayload([\n\t'limit' =\u003e 10,\n\t'offset' =\u003e 5,\n\t'status' =\u003e 'Processed'\n])-\u003esend();\n```\n\n#### POST example\n```php\n// Post a refund\n$refund = (new SnipcartApi($apiKey))-\u003epost()-\u003epayload([\n\t'token' =\u003e '6dc8e374-7e30-4dc5-9b68-2d605819e7f0',\n\t'amount' =\u003e 5.00,\n\t'comment' =\u003e \"We're refunding $5 for your order.\"\n])-\u003eto('/orders/6dc8e374-7e30-4dc5-9b68-2d605819e7f0/refunds')-\u003esend();\n```\n\n#### PUT example\n```php\n// Update a product\n$product = (new SnipcartApi($apiKey))-\u003eput()-\u003epayload([\n\t'stock' =\u003e 200,\n\t'allowOutOfStockPurchases' =\u003e false\n])-\u003eto('/products/3932ecd1-6508-4209-a7c6-8da4cc75590d')-\u003esend();\n```\n\n#### DELETE example\n```php\n// Delete an allowed domain from your Snipcart account\n$domain = (new SnipcartApi($apiKey))-\u003edelete()-\u003epayload([\n\t[\n\t\t[\n\t\t\t'domain' =\u003e 'subdomain.my-website.com',\n\t\t\t'protocol' =\u003e 'https'\n\t\t],\n\t]\n])-\u003efrom('/settings/alloweddomains')-\u003esend();\n```\n\n### Class methods\n\n#### -\u003eto(string '/url') or -\u003efrom(string '/url')\n\nThe ``to`` or ``from`` methods are identical and only exist to make your syntax make more semantic sense (``get()-\u003efrom()`` or ``post()-\u003eto()``). 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``.\n\nNote: 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``.\n\n#### -\u003epayload(array ['key' =\u003e 'value']) or -\u003epayload('key', 'value')\n\nThe ``payload`` method allows you to pass data through with your request.\n\nIf the request is a ``GET`` operation the payload will be converted to a valid query string. E.g. ``['from' =\u003e '2018-05-05', 'to' =\u003e '2019-05-05']`` will produce ``?from=2018-05-05\u0026to=2019-05-05`` and be automatically appended to your request url.\n\nAlternatively, 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. ``-\u003eget()-\u003efrom('/orders?limit=10\u0026offset=5')-\u003esend()``.\n\nIf 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.\n\n#### -\u003esend()\n\nThe ``send`` method triggers the api call to be sent and returns the response.\n\n#### -\u003eaddHeader(string 'key', string 'value')\n\nThe ``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.\n\n#### -\u003eaddHeaders(array ['key' =\u003e 'value'])\n\nThe ``addHeaders`` method accepts an associative array of key/values to set as headers for the api request.\n\n#### -\u003eresponseCode()\n\nThe ``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.\n\n#### -\u003esuccessful()\n\nThe ``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.\n\n### Checking for failed api calls\n\nSnipcart'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.\n\n```php\n$response = (new SnipcartApi($apiKey))-\u003eget()-\u003efrom('/does-not-exist')-\u003esend();\nif (!$response) {\n\t// api call failed\n}\n// else: do something with the response data...\n```\n\nAlternatively, if you prefer to split up your api call into multiple variables, the ``SnipcartApi`` class comes with a ``successful`` method.\n\n```php\n$call = (new SnipcartApi($apiKey))-\u003eget()-\u003efrom('/does-not-exist');\n$response = $call-\u003esend();\nif (!$call-\u003esuccessful()) {\n\t// api call failed\n}\n// else: do something with the response data...\n```\n\n### Using the global helper (Laravel users)\n\nIf 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.\n\n```php\nsnipcart()-\u003eget()-\u003efrom('/orders')-\u003esend();\n```\n\n### Using the facade (Laravel users)\n\nIf 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.\n\n````php\n'Snipcart' =\u003e Mtownsend\\SnipcartApi\\Facades\\SnipcartApi::class,\n````\n\n```php\nuse Snipcart;\n\nSnipcart::get()-\u003efrom('/orders')-\u003esend();\n```\n\n## Credits\n\n- Mark Townsend\n- [All Contributors](../../contributors)\n\n## Testing\n\n*Tests coming soon...*\n\nYou can run the tests with:\n\n```bash\n./vendor/bin/phpunit\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Fsnipcart-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtownsend5512%2Fsnipcart-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Fsnipcart-api/lists"}