php mautic API - 联系

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php mautic API - 联系相关的知识,希望对你有一定的参考价值。

<?php
// Bootup the Composer autoloader
include __DIR__ . '/vendor/autoload.php';  

use Mautic\Auth\ApiAuth;
use Mautic\MauticApi;

session_start();

/**-------------------------------------------------
 *  Basic authentication
*/
// ApiAuth->newAuth() will accept an array of Auth settings
$settings = array(
    'userName'   => 'hoangsoft90@gmail.com',             // Create a new user       
    'password'   => 'fmlSpibjL79f60LkNhU0'              // Make it a secure password
);
$apiUrl='https://hoangweb123.mautic.net';
// Initiate the auth object specifying to use BasicAuth
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings, 'BasicAuth');

/**-------------------------------------------------
 * Contact
*/
$api = new MauticApi();
$contactApi = $api->newApi('contacts', $auth, $apiUrl);

//list of available contact fields including custom ones.
$fields = $contactApi->getFieldList();

//get contact
$response = $contactApi->get(7);
$contact = $response[$contactApi->itemName()];
print_r($contact);

//list of notes for a specific contact
$notes = $contactApi->getContactNotes($id, $searchFilter, $start, $limit, $orderBy, $orderByDir, $publishedOnly, $minimal);

//list contacts
// getList accepts optional parameters for filtering, limiting, and ordering
$response = $contactApi->getList($filter, $start, $limit, $orderBy, $orderByDir);
$totalContacts = $response['total'];
$contact = $response[$contactApi->listName()];

//Get a list of contact’s companies the contact belongs to.
$companies = $contactApi->getContactCompanies($contactId);

//create contact
$data = array(
    'title'=> 'Your Name',
    'firstname' => 'Jim 2',
    'lastname'  => 'Contact',
    'email'     => 'jim@his-site.com',
    'phone'=> '0123456789',
    'ipAddress' => $_SERVER['REMOTE_ADDR'],
    'address1'=> 'address 1',
    'address2'=> 'address 2',
    'city'=> 'Ha noi',
    'zipcode'=> '10000',
    'country'=> 'Vietnam',
    'state'=> 'Phu Tho',
    'website'=> 'http://vtv.vn',
    'tags'=>['tag2'],
    'points'=> '0',
);

$contact = $contactApi->create($data);

//## edit a contact
$id   = 1;
$data = array(
    'email'     => 'jim-new-address@his-site.com',
    'ipAddress' => $_SERVER['REMOTE_ADDR']
);

// Create new a contact of ID 1 is not found?
$createIfNotFound = true;

$contact = $contactApi->edit($id, $data, $createIfNotFound);


//## delete contact
$response = $contactApi->delete($id);
if (isset($response['error'])) {
    echo $response['error']['code'] . ": " . $response['error']['message'];
} else {
    // do whatever with the info
}

//## Add a contact to DNC list (DO NOT CONTACT)
$data = array(
     'eventName' => 'Score via api',
     'actionName' => 'Adding',
 );
$contactApi->addDnc($contactId, $channel, $reason, $channelId, $comments);

//Remove a contact from DNC list
$contactApi->addDnc($contactId, $channel);

以上是关于php mautic API - 联系的主要内容,如果未能解决你的问题,请参考以下文章

Mautic - 亚马逊 API - Mautic 未记录退回/投诉

php mautic webhook

php mautic短信

php mautic chanel营销信息

php mautic动态内容

php mautic类别