Hey there, fellow developer! Ready to dive into the world of Odoo ERP API integration? You're in for a treat. We'll be using the awesome ang3/php-odoo-api-client
package to make our lives easier. Let's get cracking!
Before we jump in, make sure you've got:
First things first, let's get our hands on that ang3/php-odoo-api-client
package. Fire up your terminal and run:
composer require ang3/php-odoo-api-client
Easy peasy, right?
Now, let's set up those Odoo API credentials. Create a new PHP file and add this:
<?php use Ang3\Component\Odoo\Client; $client = new Client( 'https://your-odoo-instance.com', 'your_database', 'your_username', 'your_api_key' );
Boom! You're connected and ready to roll.
You've already done this in the configuration step. Pat yourself on the back!
Let's run through the basics:
$newPartner = $client->create('res.partner', [ 'name' => 'John Doe', 'email' => '[email protected]' ]);
$partner = $client->read('res.partner', $newPartner);
$client->update('res.partner', $newPartner, [ 'phone' => '123-456-7890' ]);
$client->delete('res.partner', $newPartner);
Want to find all partners named "John"? Easy:
$partners = $client->search('res.partner', [ ['name', 'like', 'John'] ]);
Odoo's got relationships? No problem:
$order = $client->read('sale.order', $orderId, ['partner_id', 'order_line']);
Got a custom Odoo method? We've got you covered:
$result = $client->execute('res.partner', 'your_custom_method', [$partnerId, 'extra_param']);
Errors happen. When they do, wrap your code in a try-catch block:
try { // Your Odoo operations here } catch (\Exception $e) { echo "Oops! " . $e->getMessage(); }
Pro tip: Enable Odoo's debug mode for more detailed error messages.
Let's create a simple order:
$orderId = $client->create('sale.order', [ 'partner_id' => $customerId, 'order_line' => [ [0, 0, [ 'product_id' => $productId, 'product_uom_qty' => 1 ]] ] ]); echo "Order created with ID: " . $orderId;
And there you have it! You're now an Odoo API integration ninja. Remember, practice makes perfect, so keep experimenting and building awesome integrations.
Need more info? Check out the official Odoo API documentation and the ang3/php-odoo-api-client GitHub repo.
Now go forth and integrate! You've got this! 🚀