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();