### Install laravel-beehiiv via Composer Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md Install the package via Composer. ```bash composer require jeffersongoncalves/laravel-beehiiv ``` -------------------------------- ### Access segments, automations, and referral program Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md Access segments, automations, and referral program resources. Each resource provides list and get methods, except referralProgram which only has get. ```php Beehiiv::segments()->list(); Beehiiv::segments()->get('seg_00000000-0000-0000-0000-000000000000'); Beehiiv::automations()->list(); Beehiiv::automations()->get('aut_00000000-0000-0000-0000-000000000000'); Beehiiv::referralProgram()->get(); ``` -------------------------------- ### Manage posts Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md List, get, create, and delete posts. The create method requires a title; status can be set to 'draft'. ```php $posts = Beehiiv::posts()->list(filters: ['status' => 'confirmed']); $post = Beehiiv::posts()->get('post_00000000-0000-0000-0000-000000000000'); $post = Beehiiv::posts()->create([ 'title' => 'Hello World', 'subtitle' => 'A short subtitle', 'status' => 'draft', ]); Beehiiv::posts()->delete('post_00000000-0000-0000-0000-000000000000'); ``` -------------------------------- ### List and get publications Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md List all publications and get a single publication by ID. Publications are not scoped to a publication ID. ```php use JeffersonGoncalves\Beehiiv\Facades\Beehiiv; $publications = Beehiiv::publications()->list(); $publication = Beehiiv::publications()->get('pub_00000000-0000-0000-0000-000000000000'); ``` -------------------------------- ### Publish beehiiv-config Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md Publish the configuration file for the package. ```bash php artisan vendor:publish --tag=beehiiv-config ``` -------------------------------- ### Configure beehiiv.php Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md Configuration file for the package. The publication_id is optional and used as the default scope when not passed explicitly. ```php // config/beehiiv.php return [ 'api_key' => env('BEEHIIV_API_KEY', ''), 'publication_id' => env('BEEHIIV_PUBLICATION_ID'), 'default_limit' => env('BEEHIIV_DEFAULT_LIMIT', 10), ]; ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md Runs the test suite for the package. Use this command to execute all tests defined in the project. ```bash composer test ``` -------------------------------- ### Set Beehiiv credentials in .env Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md Set Beehiiv credentials in the .env file. Both values are found under Settings > Integrations > API in your Beehiiv account. BEEHIIV_PUBLICATION_ID is optional; set it if most calls target a single publication. ```env BEEHIIV_API_KEY=your-api-key BEEHIIV_PUBLICATION_ID=pub_00000000-0000-0000-0000-000000000000 ``` -------------------------------- ### Manage subscriptions Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md Perform CRUD operations on subscriptions. Pass publicationId explicitly or omit it to use the configured default. The list method supports filters like email, status, tier, cursor, and expand. ```php // List (supports email, status, tier, cursor, expand filters) $subscriptions = Beehiiv::subscriptions()->list(filters: ['email' => 'jane@example.com']); $subscription = Beehiiv::subscriptions()->get('sub_00000000-0000-0000-0000-000000000000'); $subscription = Beehiiv::subscriptions()->create([ 'email' => 'jane@example.com', 'reactivate_existing' => false, 'send_welcome_email' => true, 'utm_source' => 'newsletter', ]); Beehiiv::subscriptions()->update('sub_00000000-0000-0000-0000-000000000000', ['tier' => 'premium']); Beehiiv::subscriptions()->delete('sub_00000000-0000-0000-0000-000000000000'); // Or target a different publication explicitly Beehiiv::subscriptions()->list(publicationId: 'pub_11111111-1111-1111-1111-111111111111'); ``` -------------------------------- ### Catch BeehiivException Source: https://github.com/jeffersongoncalves/laravel-beehiiv/blob/main/README.md Handle non-2xx API responses. BeehiivException exposes the decoded error body via errorBody(). ```php use JeffersonGoncalves\Beehiiv\Exceptions\BeehiivException; try { Beehiiv::subscriptions()->get('does-not-exist'); } catch (BeehiivException $e) { logger()->error($e->getMessage(), $e->errorBody()); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.