Skip to content

Instantly share code, notes, and snippets.

@martijnengler
Created February 20, 2017 17:02
Show Gist options
  • Save martijnengler/1787237263653ed42fd7c9a16e863738 to your computer and use it in GitHub Desktop.
Save martijnengler/1787237263653ed42fd7c9a16e863738 to your computer and use it in GitHub Desktop.
<?php
define("AC_MAUTIC_URL", "https://mautic.example.org/");
define("AC_MAUTIC_USER", "myusername");
define("AC_MAUTIC_PASSWORD", "mypassword");
use Mautic\Auth\ApiAuth;
use Mautic\MauticApi;
require_once __DIR__ . '/vendor/autoload.php';
// ApiAuth->newAuth() will accept an array of Auth settings
$settings = array(
'userName' => AC_MAUTIC_USER,
'password' => AC_MAUTIC_PASSWORD
);
// Initiate the auth object specifying to use BasicAuth
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings, 'BasicAuth');
$api = new MauticApi();
$contactApi = $api->newApi('contacts', $auth, AC_MAUTIC_URL . "/api");
$fields = $contactApi->getFieldList();
// creating contact works fine:
$data = array('firstname' => 'API', 'companyemail' => 'mytest@example.org', 'ipAddress' => '127.0.0.1');
$response = $contactApi->create($data);
$new_contact = $response[$contactApi->itemName()];
var_dump($new_contact);
// read-only works fine:
$response = $contactApi->get($new_contact["id"]);
var_dump($response);
// updating contact doesn't work:
// Requested URL not found: /api/contacts/74577/edit
$updatedData = array(
'firstname' => 'Updated Name'
);
$response = $contactApi->edit($new_contact["id"], $updatedData);
var_dump($response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment