A Magento 2 API Object Oriented wrapper for a Laravel application.
Install this package via Composer:
composer require grayloon/laravel-magento-api
Publish the config options:
php artisan vendor:publish --provider="Grayloon\Magento\MagentoServiceProvider" --tag="config"
Configure your Magento 2 API endpoint and token in your .env
file:
MAGENTO_BASE_URL="https://mydomain.com"
MAGENTO_ACCESS_TOKEN="client_access_token_here"
# Optional Config:
MAGENTO_BASE_PATH="rest"
MAGENTO_STORE_CODE="all"
MAGENTO_API_VERSION="V1"
You can test your connection by running tinker, then:
(new \Grayloon\Magento\Magento)->api('schema')->show();
Example:
use Grayloon\Magento\Magento;
$magento = new Magento();
$response = $magento->api('products')->all();
$response->body() : string;
$response->json() : array|mixed;
$response->status() : int;
$response->ok() : bool;
$response->successful() : bool;
$response->failed() : bool;
$response->serverError() : bool;
$response->clientError() : bool;
/V1/integration/admin/token
Generate a admin token:
$magento->api('integration')->adminToken($username, $password);
/V1/carts/mine
Returns information for the cart for the authenticated customer. Must use a single store code.
$magento->api('carts')->mine();
/V1/carts/mine/items/
Lists items that are assigned to a specified customer cart. Must have a store code.
$magento->api('cartItems')->mine();
/V1/carts/mine/items/
Add/update the specified cart item with a customer token. Must have a store code.
$magento->api('cartItems')->addItem($cartId, $sku, $quantity);
/V1/carts/mine/totals
Returns information for the cart totals for the authenticated customer. Must use a single store code.
$magento->api('cartTotals')->mine();
/V1/categories
Get a list of all categories:
$magento->api('categories')->all($pageSize = 50, $currentPage = 1, $filters = []);
/V1/integration/customer/token
Generate a customer token:
$magento->api('integration')->customerToken($username, $password);
/V1/customers/search
Get a list of customers:
$magento->api('customers')->all($pageSize = 50, $currentPage = 1, $filters = []);
/V1/guest-carts
Enable customer or guest user to create an empty cart and quote for an anonymous customer.
$magento->api('guestCarts')->create();
/V1/guest-carts/{cartId}
Return information for a specified cart.
$magento->api('guestCarts')->cart($cartId);
/V1/guest-carts/{cartId}/items
List items that are assigned to a specified cart.
$magento->api('guestCarts')->items($cartId);
/V1/guest-carts/{cartId}/items
Add/update the specified cart item.
$magento->api('guestCarts')->addItem($cartId, $sku, $quantity);
/V1/products/attributes/{attributeCode}
Retrieve specific product attribute information:
$magento->api('productAttributes')->show($attributeCode);
/V1/products/links/types
Retrieve information about available product link types:
$magento->api('productLinkType')->types();
/V1/products
Get a list of products:
$magento->api('products')->all($pageSize = 50, $currentPage = 1, $filters = []);
/V1/products/{sku}
Get info about a product by the product SKU:
$magento->api('products')->show($sku);
Get a schema blueprint of the Magento 2 REST API:
$magento->api('schema')->show();
/V1/inventory/source-items
Get a list of paginated sort items (typically used for quantity retrieval):
$magento->api('sourceItems')->all($pageSize = 50, $currentPage = 1, $filters = []);
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.