{"id":19312135,"url":"https://github.com/bigcommerce/bigcommerce-api-php","last_synced_at":"2025-05-14T15:06:55.925Z","repository":{"id":1627533,"uuid":"2339472","full_name":"bigcommerce/bigcommerce-api-php","owner":"bigcommerce","description":"Connect PHP applications with the Bigcommerce Platform","archived":false,"fork":false,"pushed_at":"2025-02-27T14:42:03.000Z","size":608,"stargazers_count":144,"open_issues_count":71,"forks_count":187,"subscribers_count":33,"default_branch":"master","last_synced_at":"2025-04-14T02:57:47.642Z","etag":null,"topics":["api-client","bigcommerce","php"],"latest_commit_sha":null,"homepage":"https://developer.bigcommerce.com","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/bigcommerce.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-09-07T04:48:46.000Z","updated_at":"2025-02-25T22:41:43.000Z","dependencies_parsed_at":"2024-04-17T04:38:42.913Z","dependency_job_id":"5bddd42b-fbe1-4a00-bc0c-e995f23fd854","html_url":"https://github.com/bigcommerce/bigcommerce-api-php","commit_stats":{"total_commits":264,"total_committers":56,"mean_commits":4.714285714285714,"dds":0.7424242424242424,"last_synced_commit":"21d51c9ef99b0670a3d788a5506612579f869d22"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigcommerce%2Fbigcommerce-api-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigcommerce%2Fbigcommerce-api-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigcommerce%2Fbigcommerce-api-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigcommerce%2Fbigcommerce-api-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigcommerce","download_url":"https://codeload.github.com/bigcommerce/bigcommerce-api-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254169328,"owners_count":22026211,"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-client","bigcommerce","php"],"created_at":"2024-11-10T00:33:03.015Z","updated_at":"2025-05-14T15:06:55.903Z","avatar_url":"https://github.com/bigcommerce.png","language":"PHP","readme":"Bigcommerce API Client\n======================\n\nPHP client for connecting to the Bigcommerce V2 REST API.\n\nTo find out more, visit the official documentation website:\nhttps://developer.bigcommerce.com/\n\n[![Latest Stable Version](https://poser.pugx.org/bigcommerce/api/v/stable.png)](https://packagist.org/packages/bigcommerce/api)\n[![Total Downloads](https://poser.pugx.org/bigcommerce/api/downloads.png)](https://packagist.org/packages/bigcommerce/api)\n\nRequirements\n------------\n\n- PHP 8.1 or greater\n- `curl` extension enabled\n\nTo generate an OAuth API token, [follow this guide.](https://support.bigcommerce.com/s/article/Store-API-Accounts)\n\n**To connect to the API with OAuth you will need the following:**\n\n- client_id\n- auth_token\n- store_hash\n\nInstallation\n------------\n\nUse the following Composer command to install the\nAPI client from [the Bigcommerce vendor on Packagist](https://packagist.org/packages/bigcommerce/api):\n\n~~~shell\n $ composer require bigcommerce/api\n $ composer update\n~~~\n\nYou can also install composer for your specific project by running the following in the library folder.\n\n~~~shell\n $ curl -sS https://getcomposer.org/installer | php\n $ php composer.phar install\n $ composer install\n~~~\n\nNamespace\n---------\n\nAll the examples below assume the `Bigcommerce\\Api\\Client` class is imported\ninto the scope with the following namespace declaration:\n\n~~~php\nuse Bigcommerce\\Api\\Client as Bigcommerce;\n~~~\n\nConfiguration\n-------------\n\nTo use the API client in your PHP code, ensure that you can access `Bigcommerce\\Api`\nin your autoload path (using Composer’s `vendor/autoload.php` hook is recommended).\n\nProvide your credentials to the static configuration hook to prepare the API client\nfor connecting to a store on the Bigcommerce platform:\n\n### OAuth\n\nIn order to obtain the auth_token you would consume `Bigcommerce::getAuthToken` method during an installation of a single-click app. Alternatively, if you already have a token, skip to `Bigcommerce::configure` and provide your credentials.\n\n~~~php\n$object = new \\stdClass();\n$object-\u003eclient_id = 'xxxxxx';\n$object-\u003eclient_secret = 'xxxxx';\n$object-\u003eredirect_uri = 'https://app.com/redirect';\n$object-\u003ecode = $request-\u003eget('code');\n$object-\u003econtext = $request-\u003eget('context');\n$object-\u003escope = $request-\u003eget('scope');\n\n$authTokenResponse = Bigcommerce::getAuthToken($object);\n\nBigcommerce::configure([\n    'client_id' =\u003e 'xxxxxxxx',\n    'auth_token' =\u003e $authTokenResponse-\u003eaccess_token,\n    'store_hash' =\u003e 'xxxxxxx'\n]);\n~~~\n\n### Basic Auth (deprecated)\n~~~php\nBigcommerce::configure([\n\t'store_url' =\u003e 'https://store.mybigcommerce.com',\n\t'username'\t=\u003e 'admin',\n\t'api_key'\t=\u003e 'd81aada4xc34xx3e18f0xxxx7f36ca'\n]);\n~~~\n\nConnecting to the store\n-----------------------\n\nTo test that your configuration was correct and you can successfully connect to\nthe store, ping the getStoreTime method which will return a DateTime object\nrepresenting the current timestamp of the store if successful or null if\nunsuccessful:\n\n~~~php\n$ping = Bigcommerce::getStoreTime();\n\nif ($ping) echo $ping-\u003eformat('H:i:s');\n~~~\n\nAccessing collections and resources (GET)\n-----------------------------------------\n\nTo list all the resources in a collection:\n\n~~~php\n$products = Bigcommerce::getProducts();\n\nforeach ($products as $product) {\n\techo $product-\u003ename;\n\techo $product-\u003eprice;\n}\n~~~\n\nTo access a single resource and its connected sub-resources:\n\n~~~php\n$product = Bigcommerce::getProduct(11);\n\necho $product-\u003ename;\necho $product-\u003eprice;\n~~~\n\nTo view the total count of resources in a collection:\n\n~~~php\n$count = Bigcommerce::getProductsCount();\n\necho $count;\n~~~\nPaging and Filtering\n--------------------\n\nAll the default collection methods support paging, by passing\nthe page number to the method as an integer:\n\n~~~php\n$products = Bigcommerce::getProducts(3);\n~~~\nIf you require more specific numbering and paging, you can explicitly specify\na limit parameter:\n\n~~~php\n$filter = ['page' =\u003e 3, 'limit' =\u003e 30];\n\n$products = Bigcommerce::getProducts($filter);\n~~~\n\nTo filter a collection, you can also pass parameters to filter by as key-value\npairs:\n\n~~~php\n$filter = ['is_featured' =\u003e true];\n\n$featured = Bigcommerce::getProducts($filter);\n~~~\nSee the API documentation for each resource for a list of supported filter\nparameters.\n\nUpdating existing resources (PUT)\n---------------------------------\n\nTo update a single resource:\n\n~~~php\n$product = Bigcommerce::getProduct(11);\n\n$product-\u003ename = 'MacBook Air';\n$product-\u003eprice = 99.95;\n$product-\u003eupdate();\n~~~\n\nYou can also update a resource by passing an array or stdClass object of fields\nyou want to change to the global update method:\n\n~~~php\n$fields = [\n\t'name'  =\u003e 'MacBook Air',\n\t'price' =\u003e 999.95\n];\n\nBigcommerce::updateProduct(11, $fields);\n~~~\n\nCreating new resources (POST)\n-----------------------------\n\nSome resources support creation of new items by posting to the collection. This\ncan be done by passing an array or stdClass object representing the new\nresource to the global create method:\n\n~~~php\n$fields = [\n\t'name' =\u003e 'Apple'\n];\n\nBigcommerce::createBrand($fields);\n~~~\n\nYou can also create a resource by making a new instance of the resource class\nand calling the create method once you have set the fields you want to save:\n\n~~~php\n$brand = new Bigcommerce\\Api\\Resources\\Brand();\n\n$brand-\u003ename = 'Apple';\n$brand-\u003ecreate();\n~~~\n\nDeleting resources and collections (DELETE)\n-------------------------------------------\n\nTo delete a single resource you can call the delete method on the resource object:\n\n~~~php\n$category = Bigcommerce::getCategory(22);\n$category-\u003edelete();\n~~~\n\nYou can also delete resources by calling the global wrapper method:\n\n~~~php\nBigcommerce::deleteCategory(22);\n~~~\n\nSome resources support deletion of the entire collection. You can use the\ndeleteAll methods to do this:\n\n~~~php\nBigcommerce::deleteAllOptionSets();\n~~~\n\nUsing The XML API\n-----------------\n\nBy default, the API client handles requests and responses by converting between\nJSON strings and their PHP object representations. If you need to work with XML\nyou can switch the API into XML mode with the useXml method:\n\n~~~php\nBigcommerce::useXml();\n~~~\n\nThis will configure the API client to use XML for all subsequent requests. Note\nthat the client does not convert XML to PHP objects. In XML mode, all object\nparameters to API create and update methods must be passed as strings\ncontaining valid XML, and all responses from collection and resource methods\n(including the ping, and count methods) will return XML strings instead of PHP\nobjects. An example transaction using XML would look like:\n\n~~~php\nBigcommerce::useXml();\n\n$xml = '\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\t\t\u003cbrand\u003e\n\t\t \t\u003cname\u003eApple\u003c/name\u003e\n\t\t \t\u003csearch_keywords\u003ecomputers laptops\u003c/search_keywords\u003e\n\t\t\u003c/brand\u003e';\n\n$result = Bigcommerce::createBrand($xml);\n~~~\n\nHandling Errors And Timeouts\n----------------------------\n\nFor whatever reason, the HTTP requests at the heart of the API may not always\nsucceed.\n\nEvery method will return false if an error occurred, and you should always\ncheck for this before acting on the results of the method call.\n\nIn some cases, you may also need to check the reason why the request failed.\nThis would most often be when you tried to save some data that did not validate\ncorrectly.\n\n~~~php\n$orders = Bigcommerce::getOrders();\n\nif (!$orders) {\n\t$error = Bigcommerce::getLastError();\n\techo $error-\u003ecode;\n\techo $error-\u003emessage;\n}\n~~~\n\nReturning false on errors, and using error objects to provide context is good\nfor writing quick scripts but is not the most robust solution for larger and\nmore long-term applications.\n\nAn alternative approach to error handling is to configure the API client to\nthrow exceptions when errors occur. Bear in mind, that if you do this, you will\nneed to catch and handle the exception in code yourself. The exception throwing\nbehavior of the client is controlled using the failOnError method:\n\n~~~php\nBigcommerce::failOnError();\n\ntry {\n\t$orders = Bigcommerce::getOrders();\n\n} catch(Bigcommerce\\Api\\Error $error) {\n\techo $error-\u003egetCode();\n\techo $error-\u003egetMessage();\n}\n~~~\n\nThe exceptions thrown are subclasses of Error, representing\nclient errors and server errors. The API documentation for response codes\ncontains a list of all the possible error conditions the client may encounter.\n\n\nVerifying SSL certificates\n--------------------------\n\nBy default, the client will attempt to verify the SSL certificate used by the\nBigcommerce store. In cases where this is undesirable, or where an unsigned\ncertificate is being used, you can turn off this behavior using the verifyPeer\nswitch, which will disable certificate checking on all subsequent requests:\n\n~~~php\nBigcommerce::verifyPeer(false);\n~~~\n\nConnecting through a proxy server\n---------------------------------\n\nIn cases where you need to connect to the API through a proxy server, you may\nneed to configure the client to recognize this. Provide the URL of the proxy\nserver and (optionally) a port to the useProxy method:\n\n~~~php\nBigcommerce::useProxy('http://proxy.example.com', 81);\n~~~\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigcommerce%2Fbigcommerce-api-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigcommerce%2Fbigcommerce-api-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigcommerce%2Fbigcommerce-api-php/lists"}