PHP code example of leadpush / sdk-php
1. Go to this page and download the library: Download leadpush/sdk-php 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/ */
leadpush / sdk-php example snippets
use Leadpush\SDK\Leadpush;
$client = new Leadpush($_ENV['LEADPUSH_API_KEY']);
$contacts = $client->contacts()->list([
'page' => 1,
'per_page' => 10,
]);
print_r($contacts->data());
use Leadpush\SDK\Leadpush;
$client = new Leadpush('leadpush_api_key', [
'baseUrl' => 'https://api.leadpush.io/v1',
'timeout' => 30000,
'headers' => [
'X-App-Name' => 'my-app',
],
]);
$contact = $client->contacts()->get('contact_uuid');
$sameContact = $client->contacts()->get('[email protected] ');
echo $contact->uuid();
echo $contact->attributes()['email'];
$contact = $client->contacts()->create([
'subscribed' => true,
'attributes' => [
'email' => '[email protected] ',
'first_name' => 'Person',
],
]);
$contact = $client->contacts()->update('contact_uuid', [
'subscribed' => false,
'attributes' => [
'first_name' => 'Updated',
],
]);
$client->contacts()->update('[email protected] ', [
'subscribed' => true,
]);
$contact = $client->contacts()->get('contact_uuid');
$contact->setSubscribed(false);
$contact->setAttribute('first_name', 'Updated');
$contact->update();
$client->contacts()->subscribe('[email protected] ');
$client->contacts()->unsubscribe('[email protected] ');
$contact->subscribe();
$contact->unsubscribe();
$events = $client->contacts()->events('contact_uuid')->list([
'search' => 'purchase',
]);
$sameEvents = $client->contacts()->events('[email protected] ')->list();
$contact = $client->contacts()->get('contact_uuid');
$events = $contact->events()->list();
$client->contacts()->events('contact_uuid')->create([
'event_name' => 'purchase',
'attributes' => [
'plan' => 'enterprise',
],
]);
$client->contacts()->events('[email protected] ')->create([
'event_name' => 'purchase',
]);
$page = $client->contacts()->list([
'page' => 1,
'per_page' => 25,
]);
print_r($page->data());
echo $page->meta()->hasNext() ? 'more' : 'done';
foreach ($client->contacts()->listAll(['per_page' => 100]) as $contact) {
echo $contact->uuid();
}
foreach ($client->contacts()->cursor(['per_page' => 100]) as $page) {
echo $page->meta()->currentPage();
echo count($page->data());
}
$domains = $client->domains()->list([
'search' => 'example',
'page' => 1,
'per_page' => 10,
]);
$domain = $client->domains()->create([
'name' => 'example.com',
'dkim_selectors' => ['default'],
'tracking_subdomain' => 'click',
'tracking_mode' => 'cloudflare',
]);
print_r($domain->dns());
$verified = $client->domains()->verify($domain->uuid());
$client->domains()->delete($domain->uuid());
$domain = $client->domains()->get('domain_uuid');
$domain->verify();
$domain->delete();
$addresses = $client->domains()->addresses('domain_uuid')->list();
$address = $client->domains()->addresses('domain_uuid')->create([
'address' => 'sender',
'display_name' => 'Sender Name',
'reply_to' => '[email protected] ',
'company_address' => '123 Main St',
'company_city' => 'New York',
'company_state' => 'NY',
'company_zip' => '10001',
'company_country' => 'US',
]);
$client->domains()->addresses('domain_uuid')->delete($address->uuid());
$domain = $client->domains()->get('domain_uuid');
$addresses = $domain->addresses()->list();
$send = $client->emails()->send([
'from' => '[email protected] ',
'subject' => 'Developer API email',
'html' => '<p>Hello world</p>',
'text' => 'Hello world',
'to' => [
'[email protected] ',
'[email protected] ',
],
'bcc' => [
'[email protected] ',
],
'reply_to' => '[email protected] ',
'headers' => [
'X-Correlation-ID' => 'abc-123',
'Auto-Submitted' => 'auto-generated',
],
]);
echo $send->isAccepted() ? 'accepted' : 'rejected';
echo $send->messageCount();
echo $send->messages()[0]['uuid'];
$fields = $client->fields()->list([
'search' => 'company',
'filters' => [
[
'id' => 'type',
'value' => ['text'],
],
],
]);
$field = $client->fields()->create([
'name' => 'company_name',
'type' => 'text',
'format' => [
'text' => 'url',
],
]);
$suppressions = $client->suppressions()->list([
'search' => '[email protected] ',
'filters' => [
[
'id' => 'type',
'value' => ['manual'],
],
],
]);
$suppression = $client->suppressions()->create([
'email' => '[email protected] ',
'type' => 'manual',
]);
$response = $client->get('contacts/contact_uuid/events');
$response = $client->post('contacts/contact_uuid/subscribe');
$client->delete('contacts/contact_uuid');
$client->get(['contacts', 'contact_uuid', 'events']);
use Leadpush\SDK\Exceptions\UnauthorizedError;
use Leadpush\SDK\Exceptions\ValidationError;
try {
$client->contacts()->list();
} catch (UnauthorizedError) {
echo 'Invalid API key';
} catch (ValidationError $error) {
print_r($error->response());
}