{"id":25519729,"url":"https://github.com/aligent/bigcommerce-v3-api-php-client","last_synced_at":"2025-04-11T00:33:06.840Z","repository":{"id":37940350,"uuid":"280055563","full_name":"aligent/bigcommerce-v3-api-php-client","owner":"aligent","description":"PHP library to interact with the BigCommerce V3 API (https://developer.bigcommerce.com/api-reference#v3-rest-api)","archived":false,"fork":false,"pushed_at":"2024-07-05T16:01:11.000Z","size":2327,"stargazers_count":13,"open_issues_count":16,"forks_count":23,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-04-02T23:46:06.461Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aligent.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":".github/CODEOWNERS","security":null,"support":null}},"created_at":"2020-07-16T04:45:17.000Z","updated_at":"2024-08-14T16:13:56.000Z","dependencies_parsed_at":"2023-02-18T10:30:27.046Z","dependency_job_id":null,"html_url":"https://github.com/aligent/bigcommerce-v3-api-php-client","commit_stats":null,"previous_names":[],"tags_count":61,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aligent%2Fbigcommerce-v3-api-php-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aligent%2Fbigcommerce-v3-api-php-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aligent%2Fbigcommerce-v3-api-php-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aligent%2Fbigcommerce-v3-api-php-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aligent","download_url":"https://codeload.github.com/aligent/bigcommerce-v3-api-php-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322773,"owners_count":21084336,"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":[],"created_at":"2025-02-19T17:29:33.050Z","updated_at":"2025-04-11T00:33:06.818Z","avatar_url":"https://github.com/aligent.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BigCommerce V3 Api Library\n\n[![Latest Release](https://img.shields.io/github/v/release/aligent/bigcommerce-v3-api-php-client?sort=semver)](https://github.com/aligent/bigcommerce-v3-api-php-client/releases)\n[![Packagist Latest](https://img.shields.io/packagist/v/aligent/bigcommerce-api-client)](https://packagist.org/packages/aligent/bigcommerce-api-client)\n![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/aligent/bigcommerce-api-client/dev-main)\n[![License](https://img.shields.io/github/license/aligent/bigcommerce-v3-api-php-client)](https://github.com/aligent/bigcommerce-v3-api-php-client/blob/main/LICENSE.md)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/aligent/bigcommerce-v3-api-php-client/php.yml?branch=main)](https://github.com/aligent/bigcommerce-v3-api-php-client/actions/workflows/php.yml)\n[![Documentation](https://img.shields.io/badge/docs-generated-success)](https://aligent.github.io/bigcommerce-v3-api-php-client/)\n## Introduction\n\nThis is an easy-to-use API client for [BigCommerce](https://developer.bigcommerce.com/api-reference).\n\n## Installation\n\nInstall [aligent/bigcommerce-api-client ](https://packagist.org/packages/aligent/bigcommerce-api-client) \nfrom packagist using [composer](https://getcomposer.org/): `composer require aligent/bigcommerce-api-client`.\n\n## Usage Examples\n\nTrivial example of updating a product name:\n\n```php\n$api = new BigCommerce\\ApiV3\\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);\n\n$product = $api-\u003ecatalog()-\u003eproduct(123)-\u003eget()-\u003egetProduct();\n$product-\u003ename = 'Updated product name';\ntry {\n    $api-\u003ecatalog()-\u003eproduct($product-\u003eid)-\u003eupdate($product);\n} catch (\\Psr\\Http\\Client\\ClientExceptionInterface $exception) {\n    echo \"Unable to update product: {$exception-\u003egetMessage()}\";\n}\n```\n\nFetching all visible products (all pages of products):\n\n```php\n$api = new BigCommerce\\ApiV3\\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);\n\n$productsResponse = $api-\u003ecatalog()-\u003eproducts()-\u003egetAllPages(['is_visible' =\u003e true]);\n\necho \"Found {$productsResponse-\u003egetPagination()-\u003etotal} products\";\n\n$products = $productsResponse-\u003egetProducts();\n```\n\nExample of updating a product variant\n\n```php\n$api = new BigCommerce\\ApiV3\\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);\n\n$productVariant = $api-\u003ecatalog()-\u003eproduct(123)-\u003evariant(456)-\u003eget()-\u003egetProductVariant();\n$productVariant-\u003eprice = '12';\n\ntry {\n    $api-\u003ecatalog()-\u003eproduct($productVariant-\u003eproduct_id)-\u003evariant($productVariant-\u003eid)-\u003eupdate($productVariant);\n} catch (\\Psr\\Http\\Client\\ClientExceptionInterface $exception) {\n    echo \"Unable to update product variant: {$exception-\u003egetMessage()}\";\n}\n```\n\nExample of creating a product variant\n\n```php\n$api = new BigCommerce\\ApiV3\\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);\n\n$productVariant = new \\BigCommerce\\ApiV3\\ResourceModels\\Catalog\\Product\\ProductVariant();\n$productVariant-\u003eproduct_id = 123;\n$productVariant-\u003esku = \"SKU-123\";\n//...\n\ntry {\n    $api-\u003ecatalog()-\u003eproduct($productVariant-\u003eproduct_id)-\u003evariants()-\u003ecreate($productVariant);\n} catch (\\Psr\\Http\\Client\\ClientExceptionInterface $exception) {\n    echo \"Unable to create product variant: {$exception-\u003egetMessage()}\";\n}\n```\n\n### API Design\n\nThere are three components to the library:\n\n- [BigCommerce/Api](./src/BigCommerce/Api) - which represent the API endpoints and tries to mimic the layout of the \n  documentation.\n  \n- [BigCommerce/ResourceModels](./src/BigCommerce/ResourceModels) - which represent the resources that are sent to and \n  received from the API, for example a `Product` or an `Order`.\n  \n- [BigCommerce/ResponseModels](./src/BigCommerce/ResponseModels) - which represent the responses from the BigCommerce \n  API.\n  \nFor additional documentation, see the [code documentation](https://aligent.github.io/bigcommerce-v3-api-php-client/).\n  \n#### API Classes\n\nTo interact with the API, always start with the [BigCommerce\\ApiV3\\Client](./src/BigCommerce/Client.php) class. All APIs\ncan be accessed in two ways: with and without an ID.\n\nIf you are querying about a specific resource instance (e.g. Product 5), then you would use singular endpoint (\n`-\u003ecatalog()-\u003eproduct(5)`), otherwise you would use the plural endpoint (i.e. `-\u003ecatalog()-\u003eproducts()`). \n\nFor example, suppose we want to find all the metafields for a brand with and id of `123`. Our query is for a _specific_\nbrand, but any metafield, so the call would look like:\n\n```php\n$api = new BigCommerce\\ApiV3\\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);\n\n$metafieldsResponse = $api-\u003ecatalog()-\u003ebrand(123)-\u003emetafields()-\u003egetAll();\n$metafields = $metafieldsResponse-\u003egetMetafields();\n```\n\nSuppose we now want to delete metafield `456` on brand `123`. Now our query is for a _specific_ brand and a _specific_ \nmetafield.\n\n```php\n$api = new BigCommerce\\ApiV3\\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);\n\n$api-\u003ecatalog()-\u003ebrand(123)-\u003emetafield(456)-\u003edelete();\n```\n\n#### Resource Model Classes\n\nThe resource models represent the resources we provided to the API and the responses we receive.\n\nTo create a new resource, simply instantiate a new object of the correct resource model and then send it to the create\nendpoint. For example, if we want to create a new brand:\n\n```php\n$api = new BigCommerce\\ApiV3\\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);\n\n$brand = new BigCommerce\\ApiV3\\ResourceModels\\Catalog\\Brand\\Brand();\n$brand-\u003ename = \"My Brand\";\n$brand-\u003emeta_description = \"My wonderful brand\";\n\n$api-\u003ecatalog()-\u003ebrands()-\u003ecreate($brand);\n```\n\n#### Response Model Classes\n\nResponses from the API all use similar response classes for consistency. There are two types generally: singular responses, \nand plural responses. Singular responses will have a single method in the format `get\u003cresource\u003e()`,\nfor example (`ProductResponse::getProduct()`). Plural responses will have two methods, a `getPagination()`\n and `get\u003cresources\u003e()` (e.g. `ProductsResponse::getProducts()`).\n\nNote that the API request is sent when the action is called and the response\nis returned.\n\n```php\n$api = new BigCommerce\\ApiV3\\Client($_ENV['hash'], $_ENV['CLIENT_ID'], $_ENV['ACCESS_TOKEN']);\n\n// Singular Responses\n$category = $api-\u003ecatalog()-\u003ecategory(456)-\u003eget()-\u003egetCategory();\n$brand    = $api-\u003ecatalog()-\u003ebrand(123)-\u003eget()-\u003egetBrand(); \n\n// Plural Responses\n$categoryResponse = $api-\u003ecatalog()-\u003ecategories()-\u003egetAll(limit: 10);\n$totalCategories  = $categoryResponse-\u003egetPagination()-\u003etotal;\n$categories       = $categoryResponse-\u003egetCategories();\n\n$brands = $api-\u003ecatalog()-\u003ebrands()-\u003egetAll()-\u003egetBrands();\n```\n\n## Development\n\n- Running tests: `composer run-script test`\n- Checking PHP style rules: `composer run-script check-style`\n- Auto fix code style rules: `composer run-script fix-style`\n\nIf you do not have composer installed, you can use the docker version: `docker run --rm -it -v $PWD:/app composer run-script check-style`\n\n### Writing Tests\n\nAll tests are located in the _tests_ folder in the namespace `BigCommerce\\Tests`. The namespace should match the class\nbeing tested after this, e.g. `BigCommerce\\Tests\\Api\\Carts` for testing `BigCommerce\\ApiV3\\Api\\Carts\\CartsApi`.\n\nResponses can be mocked using the  `BigCommerceApiTest::setReturnData()` function then you can inspect the request that\nwas made with `BigCommerceApiTest::getLastRequest()`. Response JSON files are stored in _tests/BigCommerce/responses_.\n\n## Full Documentation\n\nIf you would like to have full class documentation, run \n`docker run --rm -v /path/to/vendor/aligent/bigcommerce-api:/data phpdoc/phpdoc:3 run -d /data/src -t /data/docs --defaultpackagename BigCommerce --visibility public`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faligent%2Fbigcommerce-v3-api-php-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faligent%2Fbigcommerce-v3-api-php-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faligent%2Fbigcommerce-v3-api-php-client/lists"}