Installation
Run composer require combodo/itop-client-bundle in your Laravel project (note: this bundle is Symfony-based, so use a Laravel-compatible bridge like spatie/laravel-symfony-support if needed).
Configuration
Add the bundle’s config to config/services.php (or a custom config file):
'itop' => [
'servers' => [
'itop_server_foo' => [
'base_url' => env('ITOP_BASE_URL', 'https://itop.example.com'),
'auth_user' => env('ITOP_AUTH_USER'),
'auth_pwd' => env('ITOP_AUTH_PWD'),
'extra_headers' => ['Accept' => 'application/json'],
],
],
],
Publish the bundle’s config (if available) or manually define the service in config/services.php:
'itop_client.rest_client.itop_server_foo' => \Combodo\ItopClientBundle\RestClient\RestClient::class,
First Use Case Inject the client into a service/controller and call an iTop operation:
use Combodo\ItopClientBundle\RestClient\RestClient;
use Combodo\ItopClientBundle\RestClient\RequestOperation\Core\RequestOperationCoreCreate;
class MyController extends Controller {
public function __construct(private RestClient $itopClient) {}
public function createUser() {
$operation = new RequestOperationCoreCreate();
$operation->setData(['name' => 'John Doe', 'email' => 'john@example.com']);
$response = $this->itopClient->execute('itop_server_foo', $operation);
return response()->json($response);
}
}
Operation Execution
RequestOperation* classes (e.g., RequestOperationCoreCreate, RequestOperationCoreSearch) for common CRUD operations.$searchOp = new RequestOperationCoreSearch();
$searchOp->setFilter(['name' => 'John']);
$results = $this->itopClient->execute('itop_server_foo', $searchOp);
Dynamic Requests
$response = $this->itopClient->get('itop_server_foo', '/api/core/search', ['filter' => ['name' => 'Test']]);
Service Integration
AppServiceProvider:
public function register() {
$this->app->bind(RestClient::class, function ($app) {
return new RestClient($app['config']['itop.servers.itop_server_foo']);
});
}
RestClient directly into controllers/services.Batch Operations
/api/core/batch) for multi-record updates:
$batchOp = new RequestOperationCoreBatch();
$batchOp->setOperations([
['method' => 'create', 'data' => ['name' => 'User1']],
['method' => 'update', 'data' => ['id' => 123, 'name' => 'UpdatedUser']],
]);
$this->itopClient->execute('itop_server_foo', $batchOp);
Event Listeners
HandleIncomingWebhook or a custom listener:
use Illuminate\Http\Request;
class iTopWebhookHandler {
public function handle(Request $request) {
$data = json_decode($request->getContent(), true);
// Process iTop webhook data (e.g., trigger Laravel events)
}
}
execute() calls in try-catch blocks to handle iTop-specific errors (e.g., 400 Bad Request for invalid data):
try {
$response = $this->itopClient->execute('itop_server_foo', $operation);
} catch (\Exception $e) {
Log::error("iTop Error: " . $e->getMessage());
return response()->json(['error' => 'iTop operation failed'], 500);
}
$this->itopClient->setLogger(function ($message) {
Log::debug('iTop Client: ' . $message);
});
$cacheKey = 'itop_dropdown_categories';
$data = Cache::remember($cacheKey, 3600, function () {
return $this->itopClient->get('itop_server_foo', '/api/core/dropdowns/categories');
});
Authentication Issues
.env for credentials and ensure the iTop user has API access:
# .env
ITOP_AUTH_USER=api_user
ITOP_AUTH_PWD=secure_password
/itop/logs/) for authentication failures.Endpoint Mismatches
/api/core/create vs. /api/core/search).// Wrong: Non-existent endpoint
$this->itopClient->get('itop_server_foo', '/api/core/invalid');
// Correct: Valid search endpoint
$this->itopClient->get('itop_server_foo', '/api/core/search');
Data Format Errors
$data = ['name' => 'Test', 'email' => 'test@example.com']; // Ensure 'email' is required
$operation->setData($data);
Rate Limiting
use Symfony\Component\Process\Exception\TimeoutException;
try {
$response = $this->itopClient->execute($server, $operation, ['timeout' => 30]);
} catch (TimeoutException $e) {
sleep(2); // Retry after delay
retry();
}
Bundle Version Mismatch
Enable Verbose Logging
DEBUG:
$this->itopClient->setLoggerLevel(\Psr\Log\LogLevel::DEBUG);
storage/logs/laravel.log) for raw HTTP requests/responses.Inspect Headers
X-Debug: true):
# config/itop.php
extra_headers:
X-Debug: 'true'
Accept: 'application/json'
Test with Postman/cURL
curl -X POST "https://itop.example.com/api/core/create" \
-H "Content-Type: application/json" \
-u "api_user:secure_password" \
-d '{"name": "Test"}'
Validate iTop Server
$response = $this->itopClient->get('itop_server_foo', '/api/core/version');
RequestOperation classes:
namespace App\Itop\Operations;
use Combodo\ItopClientBundle\RestClient\RequestOperation;
class CustomOperation extends RequestOperation {
protected $endpoint = '/api/custom/endpoint';
protected $method = 'POST';
}
$this->app->bind(
\App\Itop\Operations\CustomOperation::class,
\App
How can I help you explore Laravel packages today?