Download the PHP package oscar-team/odoo-json2 without Composer
On this page you can find all versions of the php package oscar-team/odoo-json2. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package odoo-json2
Odoo JSON-2 PHP Client
A modern PHP client library for interacting with Odoo's JSON-2 API (Odoo 19+). This library provides a clean, type-safe interface for performing CRUD operations and calling custom methods on Odoo models.
Features
- ✅ Modern JSON-2 API support (Odoo 19+)
- ✅ API key-based authentication
- ✅ Full CRUD operations (Create, Read, Update, Delete)
- ✅ Type-safe with PHP 8.2+
- ✅ Comprehensive error handling
- ✅ Built on Guzzle HTTP client
- ✅ Clean, Laravel-style code structure
Requirements
- PHP 8.2 or higher
- Composer
- Odoo 19 or higher with JSON-2 API enabled
Installation
Laravel Integration
This package is designed to work seamlessly with Laravel. The service provider is automatically discovered, so no manual registration is required.
Publishing Configuration
After installing the package, publish the configuration file:
This will create a config/odoo.php file in your Laravel application.
Environment Configuration
Add the following environment variables to your .env file:
Using the Odoo Client in Laravel
The package automatically registers the Odoo class as a singleton, so you can use it via dependency injection:
Or resolve it from the service container:
Using Models in Laravel
Models are automatically booted when the service provider loads. You can use them directly:
Configuration File
The published configuration file (config/odoo.php) contains the following options:
host- Your Odoo instance URL (required)database- Database name (optional, can be determined from API key)api_key- Your Odoo API key (required)ssl_verify- Whether to verify SSL certificates (default: true)context- Additional context settings (lang, timezone, companyId)
All values can be overridden via environment variables.
Configuration
Getting Your API Key
- Log in to your Odoo instance
- Go to Settings → Users & Companies → API Keys
- Create a new API key
- Copy the generated API key
Usage
Basic Setup
Search Records
Read Records
Search and Read
Create Records
Update Records
Delete Records
Count Records
Get Model Fields
Custom Method Calls
Error Handling
Advanced Configuration
Domain Syntax
The domain syntax follows Odoo's standard format:
Examples
Working with Sales Orders
Working with Products
Eloquent-like Models
This library provides an Eloquent-like ORM for working with Odoo models, making it easy to define models with relationships and perform type-safe operations.
Basic Model Definition
Field Attributes
Use the #[Field] attribute to map Odoo fields to PHP properties:
Many-to-One Relationships (BelongsTo)
Use #[Key] to extract the ID and #[BelongsTo] to define the relationship:
One-to-Many Relationships (HasMany)
Complete Model Example
Initializing Models
Before using models, you need to boot the Odoo instance:
Querying with Models
Creating Records
Updating Records
Deleting Records
Working with Relationships
Advanced Queries
Real-World Examples
Example 1: Create a Partner with Relationships
Example 2: Find and Update Products
Example 3: Working with Invoices
Example 4: Hierarchical Partners
Testing
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This library is open-sourced software licensed under the MIT license.
Support
For issues, questions, or contributions, please open an issue on GitHub.