Fields
Use this endpoint to work with Mautic’s Contact/Company fields.
Using Mautic’s API Library
You can interact with this API through the Mautic API Library as follows, or use the various http endpoints as described in this document.
<?php
use Mautic\MauticApi;
use Mautic\Auth\ApiAuth;
// ...
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings);
$apiUrl = "https://example.com";
$api = new MauticApi();
$assetApi = $api->newApi("assets", $auth, $apiUrl);
// Get Contact field context:
$fieldApi = $api->newApi("contactFields", $auth, $apiUrl);
// Or use 'companyFields' for company fields:
$fieldApi = $api->newApi("companyFields", $auth, $apiUrl);
Get field
<?php
//...
$field = $fieldApi->get($id);
Get an individual field by ID.
HTTP Request
GET /fields/contact/ID
or GET /fields/company/ID
Response
Expected Response Code: 200
{
"field":{
"isPublished":true,
"dateAdded":"2016-11-10T13:02:52+00:00",
"createdBy":1,
"createdByUser":"Sharru-Ukin Kumar",
"dateModified":null,
"modifiedBy":null,
"modifiedByUser":null,
"id":165,
"label":"API test field",
"alias":"api_test_field11",
"type":"text",
"group":null,
"order":36,
"object":"lead",
"defaultValue":null,
"isRequired":false,
"isPubliclyUpdatable":false,
"isUniqueIdentifier":0,
"properties":[]
}
}
Field Properties
Name |
Type |
Description |
---|---|---|
|
int |
ID of the field |
|
boolean |
Published state |
|
datetime/null |
Field publish date/time |
|
datetime/null |
Field unpublish date/time |
|
|
Field creation date/time |
|
int |
ID of the User that created the field |
|
string |
Name of the User that created the field |
|
datetime/null |
Field modified date/time |
|
int |
ID of the User that last modified the field |
|
string |
Name of the User that last modified the field |
|
string |
Name of the field |
|
string |
Unique alias of the field used in the Form Field name attributes |
|
string/null |
Description of the field |
|
string |
Field type |
|
string |
Group of the fields where the field belongs |
|
int |
Order number of the field |
|
string |
Which object uses the field, Contact or Company |
|
string |
Default value of the field |
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
array |
Field options if the field type needs some. |
List Contact fields
<?php
//...
$fields = $fieldApi->getList($searchFilter, $start, $limit, $orderBy, $orderByDir, $publishedOnly, $minimal);
{
"total":71,
"fields":[
{
"isPublished":true,
"dateAdded":"2016-10-12T11:31:13+00:00",
"createdBy":1,
"createdByUser":"Judith Czinege",
"dateModified":"2016-10-12T11:31:30+00:00",
"modifiedBy":1,
"modifiedByUser":"Judith Czinege",
"id":100,
"label":"Multiselect test",
"alias":"multiselect_test",
"type":"multiselect",
"group":"core",
"order":3,
"object":"lead",
"defaultValue":null,
"isRequired":false,
"isPubliclyUpdatable":false,
"isUniqueIdentifier":false,
"properties":{
"list":[
{
"label":"PHP",
"value":"php"
},
{
"label":"JS",
"value":"js"
},
{
"label":"English",
"value":"en"
}
]
}
},
]
}
Query Parameters
Name |
Description |
---|---|
|
String or search command to filter entities by |
|
Starting row for the entities returned, defaults to 0 |
|
Limit number of entities to return, defaults to the system configuration for pagination - defaults to 30 |
|
Column to sort by, can use any column listed in the response |
|
Sort direction: |
|
Only return currently published entities |
|
Return only array of entities without additional lists in it |
HTTP Request
GET /fields/contact
or GET /fields/company
Response
Expected Response Code: 200
See JSON code example.
Field properties
Name |
Type |
Description |
---|---|---|
|
int |
ID of the field |
|
boolean |
Published state |
|
datetime/null |
Field publish date/time |
|
datetime/null |
Field unpublish date/time |
|
|
Field creation date/time |
|
int |
ID of the User that created the field |
|
string |
Name of the User that created the field |
|
datetime/null |
Field modified date/time |
|
int |
ID of the User that last modified the field |
|
string |
Name of the User that last modified the field |
|
string |
Name of the field |
|
string |
Unique alias of the field used in the Form Field name attributes |
|
string/null |
Description of the field |
|
string |
Field type |
|
string |
Group of the fields where the field belongs |
|
int |
Order number of the field |
|
string |
Which object uses the fieldContact or Company |
|
string |
Default value of the field |
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
array |
Field options if the field type needs some |
Create field
<?php
$data = array(
'label' => 'API test field',
'type' => 'text',
);
$field = $fieldApi->create($data);
Multiselect field
<?php
$data = array(
'label' => 'API test field',
'type' => 'multiselect',
'isPubliclyUpdatable' => true,
'properties' => array(
'list' => array(
array(
'label' => 'label 1',
'value' => 'value 1'
),
array(
'label' => 'label 2',
'value' => 'value 2'
)
)
)
);
$field = $fieldApi->create($data);
Create a new field.
HTTP Request
POST /fields/contact/new
or POST /fields/company/new
POST parameters
Name |
Type |
Description |
---|---|---|
|
string |
Name of the field |
|
string |
Unique alias of the field used in the Form Field name attributes |
|
string/null |
Description of the field |
|
string |
Field type |
|
string |
Group of the fields where the field belongs |
|
int |
Order number of the field |
|
string |
Which object uses the field, Contact or Company |
|
string |
Default value of the field |
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
array |
Field options if the field type needs some |
Response
Expected Response Code: 201
Properties
Same as Get Field.
Edit field
<?php
$id = 1;
$data = array(
'label' => 'API test field',
'type' => 'text',
);
// Create new a field if ID 1 isn't found?
$createIfNotFound = true;
$field = $fieldApi->edit($id, $data, $createIfNotFound);
Edit a new field. Field that this supports PUT or PATCH depending on the desired behavior.
PUT creates a field if the given ID doesn’t exist. PATCH fails if the field with the given ID doesn’t exist and updates the field values with the values field the request.
HTTP Request
To edit a field and return a 404 if the field isn’t found:
PATCH /fields/contact/ID/edit
or PATCH /fields/company/ID/edit
To edit a field and create a new one if the field isn’t found:
PUT /fields/contact/ID/edit
or PUT /fields/company/ID/edit
POST Parameters
Name |
Type |
Description |
---|---|---|
|
string |
Name of the field |
|
string |
Unique alias of the field used in the Form Field name attributes |
|
string/null |
Description of the field |
|
string |
Field type |
|
string |
Group of the fields where the field belongs |
|
int |
Order number of the field |
|
string |
Which object uses the field, Contact or Company |
|
string |
Default value of the field |
|
boolean |
|
|
boolean |
|
|
boolean |
|
|
array |
Field options if the field type needs some. |
Response
If using PUT
, the expected response code is 200
if editing the field or 201
if creating the field.
If using PATCH
, the expected response code is 200
.
Properties
Same as Get Field.
Delete field
<?php
$field = $fieldApi->delete($id);
Delete a field.
HTTP Request
DELETE /fields/contact/ID/delete
or DELETE /fields/company/ID/delete
Response
Expected Response Code: 200
Properties
Same as Get Field.