1. Go to this page and download the library: Download zdearo/meli-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zdearo / meli-php example snippets
use Zdearo\Meli\Facades\Meli;
// Get a product — returns Product DTO
$product = Meli::products()->get('MLB123456789');
$product->title; // string
$product->price; // float
$product->status; // string
// Search products — returns SearchResult DTO
$results = Meli::searchItem()->byQuery('smartphone samsung');
$results->results; // array
$results->total; // int
// Get user — returns User DTO
$user = Meli::users()->me();
$user->nickname; // string
// Get orders — returns SearchResult with Order DTOs
$orders = Meli::orders()->getBySeller(123456789);
$orders->results; // array<Order>
use Zdearo\Meli\Exceptions\MeliNotFoundException;
use Zdearo\Meli\Exceptions\MeliValidationException;
use Zdearo\Meli\Exceptions\MeliRateLimitException;
use Zdearo\Meli\Exceptions\MeliException;
try {
$product = Meli::products()->get('MLB123456789');
} catch (MeliNotFoundException $e) {
// 404 — resource not found
$e->statusCode; // 404
$e->errorCode; // "not_found"
$e->context; // full response body as array
} catch (MeliValidationException $e) {
// 400 — validation errors
$e->causes; // array of validation errors from ML
} catch (MeliRateLimitException $e) {
// 429 — too many requests
} catch (MeliException $e) {
// Catch-all for any API error
Log::error("Meli [{$e->statusCode}]: {$e->getMessage()}", $e->context);
}
// Memory-efficient — fetches pages on demand
Meli::orders()
->searchAll(['seller' => $sellerId])
->cursor()
->each(function (\Zdearo\Meli\DTO\Order $order) {
// Process each order
});
// Collect all into a Collection
$allOrders = Meli::orders()->searchAll(['seller' => $sellerId])->all();
use Zdearo\Meli\Facades\Meli;
use Zdearo\Meli\Exceptions\MeliNotFoundException;
use Illuminate\Http\Request;
class ProductController extends Controller
{
public function show(string $itemId)
{
try {
$product = Meli::products()->get($itemId);
return view('products.show', compact('product'));
} catch (MeliNotFoundException) {
abort(404);
}
}
public function search(Request $request)
{
$results = Meli::searchItem()->byQuery($request->input('q'));
return view('products.search', ['results' => $results->results, 'total' => $results->total]);
}
public function orders()
{
$orders = Meli::orders()->getBySeller(auth()->user()->meli_user_id);
return view('orders.index', ['orders' => $orders->results]);
}
}