Assets
Use this endpoint to obtain details on Mautic’s Assets.
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 Asset
<?php
//...
$asset = $assetApi->get($id);
Get an individual Asset by ID.
HTTP Request
GET /assets/ID
Response
Expected Response Code: 200
{
"asset": {
"id": 1,
"title": "Product Whitepaper",
"description": "Some description",
"alias": "whitepaper",
"language": "en",
"isPublished": true,
"publishUp": "2015-06-07T06:28:27+00:00",
"publishDown": "2015-06-30T06:28:27+00:00",
"dateAdded": "2015-06-07T06:28:27+00:00",
"createdBy": 1,
"createdByUser": "Rahel Herschel",
"dateModified": "2015-06-010T09:30:47+00:00",
"modifiedBy": 1,
"modifiedByUser": "Rahel Herschel",
"downloadCount": 10,
"uniqueDownloadCount": 8,
"revision": 1,
"category": {
"createdByUser": "Yoav Andrysiak",
"modifiedByUser": "Yoav Andrysiak",
"id": 19,
"title": "test",
"alias": "test",
"description": null,
"color": null,
"bundle": "asset"
},
"extension": "pdf",
"mime": "application/pdf",
"size": 269128,
"downloadUrl": "https://example.com/asset/1:whitepaper"
}
}
Asset Properties
Name |
Type |
Description |
---|---|---|
|
int |
ID of the Asset |
|
string |
Title/name of the Asset |
|
string/null |
Description of the Asset |
|
string |
Used to generate the URL for the Asset |
|
string |
Locale of the Asset |
|
boolean |
Published state |
|
datetime/null |
Asset publish date/time |
|
datetime/null |
Asset unpublish date/time |
|
|
Asset creation date/time |
|
int |
ID of the User that created the Asset |
|
string |
Name of the User that created the Asset |
|
datetime/null |
Asset modified date/time |
|
int |
ID of the User that last modified the Asset |
|
string |
Name of the User that last modified the Asset |
|
int |
Total number of downloads |
|
int |
Unique number of downloads |
|
int |
Revision version |
|
object/null |
Object with the Category details |
|
string |
Extension of the Asset |
|
string |
Mime type of the Asset |
|
int |
File size of the Asset in bytes |
|
string |
Public download URL for the Asset |
List assets
<?php
// ...
$assets = $assetApi->getList($searchFilter, $start, $limit, $orderBy, $orderByDir, $publishedOnly, $minimal);
HTTP Request
GET /assets
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 - default of 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 |
Response
Expected Response Code: 200
{
"total": 1,
"assets": [
{
"id": 1,
"title": "Product Whitepaper",
"description": "Some description",
"alias": "whitepaper",
"language": "en",
"isPublished": true,
"publishUp": "2015-06-07T06:28:27+00:00",
"publishDown": "2015-06-30T06:28:27+00:00",
"dateAdded": "2015-06-07T06:28:27+00:00",
"createdBy": 1,
"createdByUser": "Wayne Costa",
"dateModified": "2015-06-010T09:30:47+00:00",
"modifiedBy": 1,
"modifiedByUser": "Wayne Costa",
"downloadCount": 10,
"uniqueDownloadCount": 8,
"revision": 1,
"category": null,
"extension": "pdf",
"mime": "application/pdf",
"size": 269128,
"downloadUrl": "https://example.com/asset/1:whitepaper"
}
]
}
Properties
Same as Get Asset.
Create Asset
<?php
/**
* Local Asset example
*/
// Upload a local file first
$apiContextFiles = $this->getContext('files');
$apiContextFiles->setFolder('assets');
$fileRequest = array(
'file' => dirname(__DIR__).'/'.'mauticlogo.png'
);
$response = $apiContextFiles->create($fileRequest);
$data = array(
'title' => 'Mautic Logo sent as a API request',
'storageLocation' => 'local',
'file' => $response['file']['name']
);
$asset = $assetApi->create($data);
/**
* Remote Asset example
*/
$data = array(
'title' => 'PDF sent as a API request',
'storageLocation' => 'remote',
'file' => 'https://www.mautic.org/media/logos/logo/Mautic_Logo_DB.pdf'
);
$asset = $assetApi->create($data);
Create a new Asset. There are 2 options: local or remote Asset.
HTTP Request
POST /assets/new
POST Parameters
Name |
Type |
Description |
---|---|---|
|
string |
Asset title |
|
string |
Storage location can be local or remote |
|
string |
Either URL for remote file or filename for local file |
Response
Expected Response Code: 201
Properties
Same as Get Asset.
Edit Asset
<?php
$id = 1;
$data = array(
'type' => 'general',
);
// Create new a Asset if ID 1 isn't found?
$createIfNotFound = true;
$asset = $assetApi->edit($id, $data, $createIfNotFound);
Edit a new Asset. This supports PUT or PATCH depending on the desired behavior.
PUT creates a Asset if the given ID doesn’t exist and clears all the Asset information, adding the information from the request. PATCH fails if the Asset with the given ID doesn’t exist and updates the Asset field values with the values from the request.
HTTP Request
To edit a Asset and return a 404 if the Asset isn’t found:
PATCH /assets/ID/edit
To edit a Asset and create a new one if the Asset isn’t found:
PUT /assets/ID/edit
POST Parameters
Name |
Type |
Description |
---|---|---|
|
string |
Asset title |
|
string |
Storage location can be local or remote |
|
string |
Either URL for remote file or filename for local file |
Response
If PUT
, the expected response code if editing the Asset is 200
or 201
if created.
If using PATCH
, the expected response code is 200
.
Properties
Same as Get Asset.
Delete Asset
<?php
$asset = $assetApi->delete($id);
Delete a Asset. In case of local storage location, the local file gets deleted as well.
HTTP Request
DELETE /assets/ID/delete
Response
Expected Response Code: 200
Properties
Same as Get Asset.