PHP code example of plutolinks / loops

1. Go to this page and download the library: Download plutolinks/loops 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/ */

    

plutolinks / loops example snippets


use PlutoLinks\Loops\Loops;

$loops = Loops::client('<api-key>'); 

$response = $loops->contacts()->create([
    'email' => '[email protected]',
    'firstName' => 'John',
]);

$response->success;
$response->id;
$response->message;

$contact = $loops->contacts()->retrieve('[email protected]');

$contact->email;
$contact->firstName;
$contact->id;
$contact->lastName;
$contact->source;
$contact->subscribed;
$contact->userGroup;
$contact->userId;

$contact->favoriteColor; // Custom property

$response = $loops->contacts()->update('[email protected]', [
    'firstName' => 'John',
]);

$response->success;
$response->id;
$response->message;

$loops->contacts()->delete(email: '[email protected]');

$loops->contacts()->delete(userId: 'asdf');

$response->message;
$response->success;

$fields = $loops->contacts()->customFields();

foreach ($fields as $field) {
    $field->key;
    $field->label;
    $field->type;
}

$response = $loops->events()->send(
    eventName: 'signup',
    email: '[email protected]',
    properties: [
        'firstName' => 'John',
    ]
);

$response->success;
$response->message;

$response = $loops->transactional()->send(
    transactionalId: 'asdf',
    email: '[email protected]',
    dataVariables: [
        'url' => 'https://example.com',
    ],
    attachments: [
        [
            'contentType' => 'application/pdf', 
            'data' => '/9j/4AAQSkZJRgABAQEASABIAAD/4...', 
            'filename' => 'file.pdf', 
        ],
    ]
);

$response->success;
$response->error;
$response->message;
$response->path;
$response->transactionalId;