PHP code example of beziworld / laravel-getresponse

1. Go to this page and download the library: Download beziworld/laravel-getresponse library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

beziworld / laravel-getresponse example snippets


use Beziworld\GetResponse\Facades\GetResponse;

$result = GetResponse::subscribe(
    '[email protected]',
    'Jane Doe',
    customFields: ['city' => 'Gdansk', 'pets' => ['cat', 'dog']], // by custom field name
    tags: ['customer', 'vip'],                                    // by tag name, created when missing
);

$result->created;    // true for a new contact (created asynchronously, HTTP 202)
$result->contactId;  // ID of an existing contact

GetResponse::unsubscribe('[email protected]');

$contact = GetResponse::findContact('[email protected]');      // exact match in the default campaign
$contact->tagNames();
$contact->customField('city');                                 // ['Gdansk']

$page = GetResponse::contacts(['campaignId' => 'V3J', 'createdOn' => ['from' => now()->subWeek()]], perPage: 1000);
$page->totalCount;

GetResponse::allContacts(['campaignId' => 'V3J'])->each(fn ($contact) => ...); // every page

GetResponse::createContact('[email protected]', 'V3J', ['name' => 'John', 'dayOfCycle' => 0]);
GetResponse::createContacts([['email' => '[email protected]'], ['email' => '[email protected]']], 'V3J'); // batch
GetResponse::updateContact($contact->contactId, ['name' => 'Jane Smith']);  // tags and fields given here replace
GetResponse::addTags($contact->contactId, ['hR']);                          // by tag ID, keeps the others
GetResponse::setCustomFields($contact->contactId, ['kL6Nh' => 'Sopot']);    // by field ID, keeps the others
GetResponse::contactActivities($contact->contactId);
GetResponse::deleteContact($contact->contactId);

use Beziworld\GetResponse\Concerns\SyncsWithGetResponse;

class User extends Model
{
    use SyncsWithGetResponse;

    public function getResponseCustomFields(): array
    {
        return ['city' => $this->city, 'plan' => $this->plan];
    }

    public function getResponseTags(): array
    {
        return $this->is_customer ? ['customer'] : [];
    }

    public function shouldSyncWithGetResponse(): bool
    {
        return $this->newsletter_consent;
    }
}

dispatch(fn () => $user->syncToGetResponse());   // recommended: queued
$user->removeFromGetResponse();

GetResponse::campaigns()->items;
GetResponse::findCampaign('my_list');
GetResponse::createCampaign('new_list', ['languageCode' => 'PL']);

GetResponse::tags()->items;
GetResponse::findTag('vip');
GetResponse::createTag('vip');

GetResponse::customFields()->items;
GetResponse::createCustomField('pets', 'checkbox', 'checkbox', ['cat', 'dog']);

GetResponse::autoresponders(['campaignId' => 'V3J'])->items;
GetResponse::autoresponder('Q');
GetResponse::newsletters(['status' => 'sent'])->items;
GetResponse::newsletterStatistics('N1');
GetResponse::createNewsletter([...]);   // documented body: subject, campaign, fromField, content, sendSettings
GetResponse::cancelNewsletter('N1');

use Beziworld\GetResponse\Messages\TransactionalEmail;

$id = GetResponse::sendTransactional(
    TransactionalEmail::create('Your order #1001')
        ->from('V')                       // fromFieldId
        ->to('[email protected]', 'Jane')
        ->html('<p>Thank you!</p>')
        ->plain('Thank you!')
        ->tag('vBd5')                     // optional tag ID for statistics
        ->attachData($pdf, 'invoice.pdf', 'application/pdf')
);

GetResponse::sendTransactional(TransactionalEmail::create()->from('V')->to('[email protected]')
    ->template('tpl1', ['name' => 'Jane']));

GetResponse::transactionalEmail($id);
GetResponse::transactionalStatistics('day', ['timeFrame' => ['from' => now()->subWeek()]]);

   GetResponse::enableCallbacks(route('getresponse.callback', ['secret' => config('getresponse.connections.default.webhook_secret')]), ['subscribe', 'unsubscribe']);
   

   use Beziworld\GetResponse\Events\ContactBounced;
   use Beziworld\GetResponse\Events\ContactUnsubscribed;

   Event::listen(fn (ContactUnsubscribed $event) => User::where('email', $event->event->email)->update(['newsletter_consent' => false]));
   Event::listen(fn (ContactBounced $event) => User::where('email', $event->event->email)->update(['email_bounced_at' => now()]));
   

GetResponse::contacts();
GetResponse::rateLimit()?->remaining;      // X-RateLimit-Remaining
GetResponse::rateLimit()?->resetInSeconds; // X-RateLimit-Reset

'connections' => [
    'default' => ['api_key' => env('GETRESPONSE_API_KEY'), 'campaign_id' => env('GETRESPONSE_CAMPAIGN_ID')],
    'max' => ['api_key' => env('GETRESPONSE_MAX_API_KEY'), 'environment' => 'max-pl', 'domain' => 'newsletter.example.pl'],
],

GetResponse::connection('max')->subscribe('[email protected]');
GetResponse::using(['api_key' => decrypt($tenant->gr_key), 'campaign_id' => $tenant->gr_list]);
GetResponse::using(['access_token' => $oauthToken]);   // OAuth 2.0 (Authorization: Bearer)
GetResponse::resolveWebhookSecretsUsing(fn () => Tenant::pluck('gr_webhook_secret', 'id')->all());

Http::fake(['api.getresponse.com/v3/*' => Http::response([])]);

$user->syncToGetResponse();

Http::assertSent(fn ($request) => str_starts_with($request->url(), 'https://api.getresponse.com/v3/contacts'));