PHP SDK overview
Build commerce applications with PHP.
The PHP SDK (also referred to as the PHP v2 SDK) enables you to use methods and objects to interact with Composable Commerce APIs rather than using plain HTTP calls and untyped JSON objects. With the PHP SDK, you can make use of IDE autocompletion, type-safety, encapsulation, and an internal domain-specific language for formulating valid requests.
The PHP SDK is autogenerated using our open-source code generator to provide faster releases of new features and bug fixes.
Every commercetools API is supported, including the Import API using the Import API Request Builder.
Get started
Learn how to set up and use the PHP SDK with our get started guide.
Refer to our integration tests for examples of creating, querying, updating, and deleting resources in your Composable Commerce Project.
The PHP SDK is fully open source and is available on GitHub under the MIT License, where you can also find its release notes.
You can view the full PHP SDK reference on GitHub.
Migration from v1
Learn how to migrate to the PHP v2 SDK by following our guide on GitHub.
SDK features
The PHP SDK utilizes various standard interfaces and components to ensure consistency and interoperability:
- JSON serializer
- PSR-3 - LoggerInterface
- PSR-4 - Autoloader
- PSR-6 - CachingInterface
- PSR-7 - HTTP Message Interface
- PSR-16 - Common Interface for Caching Libraries
- PSR-18 - HTTP Client
- PHP Date API:
The PHP SDK reference includes example usage of these interfaces and components.
The SDK also simplifies development with:
- Client interfaces: the HTTP client abstract is a functional interface and can be replaced with test doubles.
- Model factory methods: each model has a factory method
::of()
to create a new empty instance.
Best practices and error handling
If you encounter an issue using the PHP SDK, please report it in the GitHub repository. If the issue is urgent or critical for your business, contact the Composable Commerce support team. You should provide as many details as possible with your issue reports, including the SDK version, specific error messages, any log or stack traces, and the code snippet that causes the issue.
Exceptions
The PHP SDK uses exceptions from the base class Exception (such as InvalidArgumentException) and provides its own exceptions which inherit from BaseException.
JSON serializing and deserializing problems throw JsonException.
ApiClientException expresses errors which can be recovered by the client (HTTP status code >= 400 and < 500). ApiServerException expresses errors which can be recovered by the server (HTTP status code >= 500).
Errors
If a command cannot be performed due to unfulfilled preconditions, one error response with multiple errors can be returned. For more information, see HTTP API Errors.