Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Code Block
languagephp
<?php
require "../vendor/autoload.php";

use de\xqueue\maileon\api\client\contacts\ContactsService;
use de\xqueue\maileon\api\client\contacts\Contact;
use de\xqueue\maileon\api\client\contacts\Permission;
use de\xqueue\maileon\api\client\contacts\StandardContactField;
use de\xqueue\maileon\api\client\contacts\SynchronizationMode;
use de\xqueue\maileon\api\client\contacts\Preference;

function synchronizeMaileonContacts() {
    $maileon_config = array(
        'BASE_URI' => 'https://api.maileon.com/1.0',
        'API_KEY' => 'api_kulcs',
        'TIMEOUT' => 5
    );

    $contacts = [
        new Contact(null, 'test@maileon.hu', Permission::$DOI_PLUS, -1, false, [
            StandardContactField::$FIRSTNAME => 'Jakab',
            StandardContactField::$LASTNAME => 'Gipsz',
        ], [
            'custom_field1' => 'Egy érték'
        ], null, null, [
            new Preference('EmailSegment1', null, 'Email', true),
            new Preference('EmailSegment2', null, 'Email', false),
            new Preference('EmailSegment3', null, 'Email', false),
            new Preference('EmailSegment4', null, 'Email', true)
        ]),
        new Contact(null, 'test2@maileon.hu', Permission::$DOI_PLUS, -1, false, [
            StandardContactField::$FIRSTNAME => 'János',
            StandardContactField::$LASTNAME => 'Kovács',
        ], [
            'custom_field1' => 'Egy másik érték'
        ], null, null, [
            new Preference('EmailSegment1', null, 'Email', false),
            new Preference('EmailSegment2', null, 'Email', false),
            new Preference('EmailSegment3', null, 'Email', true),
            new Preference('EmailSegment4', null, 'Email', true)
        ])
    ];

    $ignoreInvalid = true;
    $reimportUnsubscribed = false;
    $overridePermission = false;
    $updateOnly = false;

    $contacts_service = new ContactsService($maileon_config);
    $response = $contacts_service->synchronizeContacts(
        $contacts,
        Permission::$DOI_PLUS,
        SynchronizationMode::$UPDATE,
        false,
        $ignoreInvalid,
        $reimportUnsubscribed,
        $overridePermission,
        $updateOnly
    );

    if($response->isSuccess()) {
        echo 'Sikeres szinkronizáció!';
    } else {
        echo 'Sikertelen szinkronizáció';

        echo '<pre>';
        echo $response->getBodyData();
        echo '</pre>';
    }
}

synchronizeMaileonContacts();