- What Laravel versions does spatie/laravel-harvest-sdk support?
- The package targets Laravel 8.x and 9.x, as indicated by Spatie’s typical versioning patterns. Always check the package’s `composer.json` or GitHub for the exact supported range, but it aligns with modern Laravel LTS releases. For older versions, you may need a legacy fork or manual adjustments.
- How do I handle OAuth2 token refreshes with this SDK?
- The SDK abstracts OAuth2 authentication, but token refreshes may require manual handling if Harvest’s API returns a 401 error. Store tokens securely in Laravel’s config or cache, and implement a fallback to refresh tokens using Harvest’s OAuth2 endpoint. The SDK likely provides a base client class to extend for custom logic.
- Can I sync Harvest time entries to a Laravel Eloquent model?
- Yes, you can map Harvest resources to Eloquent models by extending the SDK’s base classes or creating custom repositories. For example, fetch a time entry via `$harvest->timeEntries()->find($id)` and hydrate a local `TimeEntry` model. Use Laravel’s accessors/mutators to bridge Harvest’s fields to your schema.
- Does this SDK support Harvest webhooks for real-time updates?
- The SDK does not natively support webhooks, but you can integrate them by creating a Laravel route to handle Harvest’s POST requests, then dispatch events or queue jobs (e.g., `harvest:handle-webhook`) to process updates. Use `spatie/laravel-webhooks` or custom middleware to validate signatures and route payloads.
- How do I test my application if it relies on the Harvest API?
- Mock the SDK using Laravel’s HTTP testing or Mockery. Stub the `Harvest` facade or service container binding to return predefined responses. For contract testing, validate SDK outputs against Harvest’s OpenAPI spec with tools like `vcr/php-vcr` to record and replay API interactions without hitting live endpoints.
- What if the SDK doesn’t cover an endpoint I need, like invoicing?
- The SDK is intentionally partial—contribute missing features via GitHub PRs or extend it by creating a custom wrapper around the base `HarvestClient`. For critical paths, fall back to raw Guzzle HTTP calls using the SDK’s configuration (e.g., `config('harvest.api_url')`) to maintain consistency in error handling and retries.
- How does the SDK handle Harvest’s API rate limits?
- The SDK likely includes retry logic with exponential backoff for rate-limited requests (HTTP 429). Configure retries in the published config file (e.g., `harvest.php`) by setting `max_retries` and `retry_delay`. Monitor failed requests with Laravel’s logging or a package like `spatie/laravel-monitor` to alert on throttling.
- Can I use this SDK in a queue job for batch operations?
- Yes, offload API calls to Laravel queues (e.g., `harvest:sync-projects`) to avoid timeouts. Use `spatie/queueable-side-effects` for idempotency if retries are needed. Batch operations like bulk time entry creation should be paginated or chunked to respect Harvest’s rate limits and avoid memory issues.
- Is there a performance impact when fetching large datasets from Harvest?
- The SDK may not optimize for large payloads, so implement pagination manually (e.g., `?page=1&per_page=100`) or use Harvest’s bulk endpoints if available. For memory-intensive operations, stream responses or process data in chunks. Test with realistic datasets to identify bottlenecks in your Laravel application.
- What are the alternatives to spatie/laravel-harvest-sdk?
- Consider Harvest’s official PHP SDK for full API coverage, though it may lack Laravel integrations. For lightweight needs, use raw Guzzle HTTP calls with Laravel’s HTTP client. If you need a more maintained package, evaluate `spatie/laravel-webhook-client` for webhook handling or build a custom wrapper using `spatie/array-to-object` for API responses.