This plugin provides REST API endpoints to retrieve information about Craft CMS fields, sections, entry types, sites, and users. It's specifically designed to work with Craft CMS 5.x and handles the new matrix field structure (Entry fields).
The API provides structured information about your Craft CMS installation, making it easy to integrate with external services like translation management systems.
composer require smartcat-ai/craft-smartcat-integration php craft plugin/install smartcat-integration
All endpoints are configured to allow anonymous access for easy integration.
Endpoint: GET /api/smartcat/fields
Parameters:
sectionHandle(required) - The handle of the sectiontypeHandle(required) - The handle of the entry typesectionId(optional) - The ID of the section for optimization
Description: Returns entry types and field types for a specific section and entry type.
Example Request:
GET /api/smartcat/fields?sectionHandle=test_section_structure&typeHandle=testTypeSimple
Example Response:
{
"entryTypes": [
{
"typeHandle": "testTypeSimple",
"typeName": "Test type simple",
"displayName": "Test type simple",
"typeId": 1,
"fieldTypes": ["title", "content"]
}
],
"fieldTypes": [
{
"typeHandle": "content",
"typeName": "richtext",
"displayName": "Content",
"typeId": 1,
"isLocalizable": true,
"graphQLMode": "raw",
"matrixEntryTypes": [],
"neoBlockTypes": {}
},
{
"typeHandle": "neoField1",
"typeName": "neo",
"displayName": "Neo Field 1",
"typeId": 12,
"isLocalizable": true,
"graphQLMode": null,
"matrixEntryTypes": [],
"neoBlockTypes": {
"block1": ["block1", "myType2"],
"myType2": []
}
}
]
}Endpoint: GET /api/smartcat/sections
Description: Returns information about all sections in the Craft CMS installation.
Example Response:
[
{
"id": 4,
"handle": "test_section_structure",
"name": "Test section structure",
"type": "structure"
}
]Endpoint: GET /api/smartcat/types
Parameters:
sectionHandle(optional) - The handle of the sectionsectionId(optional) - The ID of the section
Note: Either sectionHandle or sectionId is required.
Description: Returns all entry types for a specific section.
Example Request:
GET /api/smartcat/types?sectionHandle=test_section_structure
Example Response:
[
{
"id": 4,
"handle": "testTypeSimple",
"name": "test_type_simple",
"sectionId": 4,
"sectionHandle": "test_section_structure",
"sectionName": "Test section structure",
"hasTitleField": true,
"titleTranslationMethod": "site",
"titleTranslationKeyFormat": null,
"titleFormat": null,
"fieldsCount": 2
}
]Endpoint: GET /api/smartcat/sites
Description: Returns information about all sites configured in Craft CMS.
Example Response:
[
{
"id": 1,
"handle": "default",
"name": "Default Site",
"language": "en-US",
"primary": true,
"enabled": true,
"baseUrl": "@web/",
"hasUrls": true
}
]Endpoint: GET /api/smartcat/meta
Description: Returns the same contract as fields, but for all entry types and all fields in the system.
The API automatically maps Craft CMS field types to more readable names:
| Craft CMS Field Type | API Field Type |
|---|---|
| PlainText | string |
| Textarea | text |
| RichText | richtext |
| CKEditor Field | richtext |
| Number | number |
| Url | url |
| Date | date |
| Lightswitch | boolean |
| Dropdown | select |
| Checkboxes | multiselect |
| RadioButtons | radio |
| Entries | entries |
| Categories | categories |
| Assets | assets |
| Users | users |
| Tags | tags |
| Matrix | matrix |
| Neo | neo |
| Table | table |
For Neo fields, neoBlockTypes returns a hierarchy object:
{
"parentHandle": ["childHandle1", "childHandle2"],
"childHandle1": []
}Each Neo block type includes comprehensive metadata about its configuration:
The childBlocks field defines which block types can be nested as children:
trueor"*"- All block types can be children["handle1", "handle2"]- Only specific block types can be children (array of handles)falseornull- No child blocks allowed
Example:
{
"metadata": {
"childBlocks": ["textBlock", "imageBlock"],
"minChildBlocks": 1,
"maxChildBlocks": 5
}
}This means:
- Only
textBlockandimageBlocktypes can be added as children - Must have at least 1 child block
- Can have up to 5 child blocks
enabled- Whether the block type is enableddescription- Block type descriptionchildBlocks- Which block types can be children (see above)topLevel- Whether this block type can be at the top levelgroupChildBlockTypes- Whether to group child block types in the UIminBlocks- Minimum number of this block type allowedmaxBlocks- Maximum number of this block type allowedminChildBlocks- Minimum number of child blocks requiredmaxChildBlocks- Maximum number of child blocks allowedminSiblingBlocks- Minimum number of sibling blocks at the same levelmaxSiblingBlocks- Maximum number of sibling blocks at the same level
The API handles complex nested structures with full recursion:
- Neo within Neo - Nested Neo fields export complete
neoFieldInfowith all block types - Matrix within Neo - Nested Matrix fields export complete
matrixFieldInfowith all entry/block types - Neo within Matrix - Nested Neo fields export complete
neoFieldInfowith all block types - Matrix within Matrix - Nested Matrix fields export complete
matrixFieldInfo(Craft 5)
Important: Nested fields export the same complete structure as top-level fields:
- Matrix fields always include
matrixFieldInfo(whether nested or not) - Neo fields always include
neoFieldInfo(whether nested or not) - All block types, entry types, and fields are fully exported
- No information is lost due to nesting
In Craft CMS 5, the matrix field system has been completely redesigned:
- Matrix blocks are now entries - What used to be matrix blocks are now regular entries
- Block types are now entry types - The old
getBlockTypes()method no longer exists - Use
getEntryTypes()- Matrix fields now usegetEntryTypes()to get available entry types - Nested structure - Matrix fields can contain other matrix fields, creating complex nested structures
When a matrix field is detected, the API adds a matrixFieldInfo object containing:
Lists all available entry types for this matrix field:
{
"fieldType": "entryType",
"fieldName": "entryTypeHandle",
"displayName": "Entry Type Name",
"typeIds": ["entryTypeHandle"]
}Detailed information about each entry type, including their fields:
{
"typeHandle": "entryTypeHandle",
"typeName": "Entry Type Name",
"typeId": 123,
"childFields": [
{
"fieldType": "richtext",
"fieldName": "content",
"displayName": "Content",
"isLocalizable": true
}
]
}The API handles nested matrix fields (matrix fields within matrix entry types) by:
- Detecting nested matrix fields - Checks if any field within an entry type is also a matrix field
- Adding
typeIdsarray - Lists all available entry types for nested matrix fields - Preventing infinite recursion - Includes safety measures for complex nested structures
Each matrix field includes debug information to help troubleshoot:
{
"debug": [
"Matrix field ID: 3",
"Matrix field handle: testMatrixField",
"Craft version: 5.7.7",
"Field class: craft\\fields\\Matrix",
"getEntryTypes() returned 2 entry types",
"Final entry types count: 2",
"Entry type testTypeNested has 1 custom fields",
"Entry type testTypeSimple has 2 custom fields",
"Nested matrix field testMatrixField has 2 entry types"
]
}The API includes comprehensive error handling:
- Missing parameters - Returns 400 Bad Request with descriptive error messages
- Invalid section/type handles - Returns 400 Bad Request if sections or entry types don't exist
- Matrix field processing errors - Returns error information within the matrix field response
- Field processing errors - Individual field errors don't break the entire response
- Craft CMS 5.x - Fully supported with new matrix field structure
- Craft CMS 4.x and below - May require modifications for matrix field handling
No plugins are required for basic functionality.
- Plugin Handle:
neo - Namespace:
benf\neo - What it provides: Advanced Matrix-like field with hierarchical blocks, groups, and conditions
- API Support: Full support for Neo fields including:
- All block types and their configurations
- Nested fields within blocks
- Block type metadata (enabled, description, child blocks settings, etc.)
- Nested Neo and Matrix fields within Neo blocks
If the Neo plugin is not installed, Neo field detection will simply not trigger and the fields will be reported as their base type.
Use the included fetch-local.ps1 PowerShell script to test the API locally:
./fetch-local.ps1This script:
- Copies the source files to your local Craft CMS installation
- Makes a test API request
- Displays the formatted response
The script tests the fields endpoint with:
GET /api/smartcat/fields?sectionHandle=test_section_structure&typeHandle=testTypeSimple
When contributing to this project:
- Test with Craft CMS 5 - Ensure compatibility with the latest Craft CMS version
- Handle matrix fields properly - Use
getEntryTypes()instead of deprecatedgetBlockTypes() - Include error handling - Add appropriate try/catch blocks for new functionality
- Update documentation - Keep this README updated with any new features or changes
This project is licensed under the terms specified in the LICENSE file.