SDKs overview
Magento (Adobe Commerce) provides an extensive set of APIs for managing various aspects of an e-commerce store, including product catalogs, customer data, orders, and payments. To facilitate interaction with these APIs, developers can utilize a combination of official and community-contributed SDKs and libraries. These tools aim to abstract the underlying HTTP requests, authentication mechanisms, and JSON parsing, allowing developers to focus on business logic rather than API communication specifics.
While Magento's core platform is built on PHP, its APIs are designed to be consumed by any language. This page focuses on the most commonly used SDKs and libraries for PHP and JavaScript, which are frequently employed for backend integrations and frontend storefront development, respectively. The official documentation emphasizes direct HTTP calls and provides comprehensive API references, serving as the primary guide for all integrations, regardless of SDK use.
Developers working with Magento APIs often encounter three main types of APIs: Admin APIs for backend management, Storefront APIs for customer-facing interactions, and Integration APIs for connecting third-party systems. Each API type may have specific authentication requirements and endpoints, which SDKs typically help manage. For a full understanding of the API types, consult the official Magento API quick reference.
Official SDKs by language
Adobe Commerce (Magento) primarily provides comprehensive documentation and API specifications rather than traditional, full-featured SDKs with pre-built client libraries for every language. The recommended approach for interacting with the Magento API often involves making direct HTTP requests based on the Magento REST API documentation. However, the PHP framework itself, upon which Magento is built, includes tools and patterns that function similarly to an SDK for module development and internal API calls.
For external applications, developers typically generate API clients from the OpenAPI Specification (formerly Swagger) files provided by Magento, or construct HTTP requests manually. While a dedicated, standalone "Magento API SDK" analogous to those for platforms like Stripe or Twilio is not a central offering, the framework provides robust internal mechanisms for API consumption and extension. The following table outlines the primary approaches and tools available:
| Language | Package/Approach | Install Command/Method | Maturity/Notes |
|---|---|---|---|
| PHP (Internal/Module Dev) | Magento Framework Components | Composer (part of Magento core) | Core framework; stable and actively maintained for internal use within Magento modules. |
| PHP (External Client) | Generated OpenAPI Client / Guzzle HTTP | composer require guzzlehttp/guzzle |
Custom generation from Magento's OpenAPI spec or manual HTTP client; stable. |
| JavaScript (Frontend) | PWA Studio / GraphQL Client | npm install @apollo/client graphql |
Official Adobe PWA Studio for headless Magento; stable and actively developed. |
| JavaScript (External Client) | Fetch API / Axios | npm install axios (for Axios) |
Manual HTTP requests; stable and widely used for external web applications. |
Installation
Installation methods vary depending on whether you are developing within the Magento framework or building an external application. For internal PHP module development, components are part of the Magento installation itself, managed by Composer.
PHP (External Client - Guzzle Example)
For external PHP applications interacting with the Magento REST API, a common approach is to use an HTTP client like Guzzle. First, install Guzzle via Composer:
composer require guzzlehttp/guzzle
Then, you can make API requests. Authentication typically involves obtaining an access token. The Magento documentation details token-based authentication, which is recommended for third-party integrations.
JavaScript (PWA Studio - GraphQL Client)
For headless Magento development using PWA Studio, a GraphQL client like Apollo Client is standard. PWA Studio is an official Adobe initiative providing tools for building modern storefronts based on GraphQL APIs.
npm install @apollo/client graphql
Integration within a PWA Studio project would involve configuring the Apollo Client to point to your Magento GraphQL endpoint and defining your GraphQL queries and mutations.
JavaScript (External Client - Axios Example)
For external JavaScript applications (e.g., a custom frontend or Node.js backend) interacting with the Magento REST API, Axios is a popular choice for making HTTP requests:
npm install axios
Similar to PHP, you would then configure Axios with the base URL and handle authentication headers, such as bearer tokens obtained from Magento's authentication endpoints. For details on obtaining these tokens, refer to the Magento token authentication guide.
Quickstart example
This example demonstrates how to fetch a list of products using an external PHP application with Guzzle, assuming you have an administrator access token.
PHP Quickstart (Fetching Products)
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
$baseUrl = 'https://your-magento-instance.com/rest/V1/';
$accessToken = 'YOUR_MAGENTO_ADMIN_ACCESS_TOKEN'; // Obtain this from Magento admin or integration creation
$client = new Client([
'base_uri' => $baseUrl,
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'Content-Type' => 'application/json',
],
]);
try {
$response = $client->request('GET', 'products?searchCriteria[pageSize]=10');
$products = json_decode($response->getBody()->getContents(), true);
echo "Fetched products:\n";
foreach ($products['items'] as $product) {
echo "- " . $product['name'] . " (SKU: " . $product['sku'] . ")\n";
}
} catch (GuzzleException $e) {
echo "Error: " . $e->getMessage() . "\n";
if ($e->hasResponse()) {
echo "Response: " . $e->getResponse()->getBody()->getContents() . "\n";
}
}
?>
Before running this code:
- Replace
https://your-magento-instance.com/with your actual Magento store URL. - Replace
YOUR_MAGENTO_ADMIN_ACCESS_TOKENwith a valid access token. You can generate an integration token within the Magento Admin panel underSystem > Integrations, or obtain a customer token via the Magento API authentication process. - Ensure Guzzle is installed via Composer.
JavaScript Quickstart (Fetching Products with Axios)
This example uses Axios to fetch product data from a Magento instance.
const axios = require('axios');
const baseUrl = 'https://your-magento-instance.com/rest/V1/';
const accessToken = 'YOUR_MAGENTO_ADMIN_ACCESS_TOKEN'; // Obtain this from Magento admin or integration creation
async function getProducts() {
try {
const response = await axios.get(`${baseUrl}products?searchCriteria[pageSize]=10`, {
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
});
console.log('Fetched products:');
response.data.items.forEach(product => {
console.log(`- ${product.name} (SKU: ${product.sku})`);
});
} catch (error) {
console.error('Error fetching products:', error.response ? error.response.data : error.message);
}
}
getProducts();
Before running this code:
- Replace
https://your-magento-instance.com/with your actual Magento store URL. - Replace
YOUR_MAGENTO_ADMIN_ACCESS_TOKENwith a valid access token. - Ensure Axios is installed via npm.
Community libraries
Given Magento's modular nature and large developer community, several unofficial or community-maintained libraries and tools exist to aid in development. These often provide higher-level abstractions or specialized functionalities not found in the core framework or official documentation.
- PHP Magento 2 API Client Libraries: Various open-source projects on GitHub offer PHP clients that wrap Magento's REST API. These clients often aim to provide a more object-oriented interface than direct HTTP calls, simplifying common operations. Developers should evaluate these based on their specific needs, maintenance status, and compatibility with their Magento version. A search on platforms like GitHub for Magento 2 API client libraries can reveal options.
- Magento 2 SOAP API Clients: While REST is the primary modern API, Magento also supports SOAP. Community libraries for SOAP clients exist for those integrating with older systems or specific Magento functionalities that might still rely on SOAP.
- JavaScript/TypeScript Libraries: Beyond PWA Studio, some community efforts focus on creating lightweight JavaScript wrappers for specific Magento API endpoints or providing utility functions for common frontend tasks involving Magento data. These can be particularly useful for custom headless frontends not using PWA Studio.
- Integration Service Connectors: Many integration platform as a service (iPaaS) solutions and enterprise service buses (ESB) offer pre-built connectors for Magento. While not SDKs in the traditional sense, these connectors abstract the API calls and authentication, allowing for low-code or no-code integrations with other systems. Examples include platforms like Tray.io's Magento 2 connector, which provide pre-built workflows and data mapping capabilities.
When considering community libraries, it is important to assess their documentation, active maintenance, community support, and licensing. Relying on well-maintained, popular projects can mitigate risks associated with unsupported codebases. Always cross-reference with the official Magento developer documentation to ensure compatibility and adherence to best practices.