Contentstack CLI lets you use the Audit plugin to perform audit operations on the exported stack data, helping you identify and fix issues.
The Audit plugin provides users with detailed reports about any issues related to the following, in a given stack data:
Additionally, it includes commands that validate and resolve these issues, including missing references, invalid field values, missing mandatory fields, incomplete publish details, field rule violations, and content type mismatches.
This step-by-step guide lets you install and use the Audit plugin in CLI.
The Audit plugin lets you perform the following operation in Contentstack CLI:
The cm:stacks:audit command allows you to validate exported stack data and identify various issues across all supported modules.
csdx cm:stacks:audit
Note: If you exported data from a branch-enabled stack, make sure to provide the complete local path up to the branch. For example, C:\Users\...\CLI\Content\branch_folder.
You successfully ran an audit operation to find data issues in your stack.
Alternatively, you can pass the path in the command as given below:
csdx cm:stacks:audit --data-dir <path>csdx cm:stacks:auditOptions
Note: If the custom role or the workflow module has branches enabled and you want audit to operate on all the branches except a particular branch, then you can provide that specific branch name using the --config flag as given below:
{
"branch": "<branch-name>"
}Examples
csdx cm:stacks:audit --report-path <path>csdx cm:stacks:audit --report-path <path> --csvcsdx cm:stacks:audit --report-path <path> --filter="name=<filter-value>"csdx cm:stacks:audit --report-path <path> --modules=content-typesThe cm:stacks:audit:fix command allows you to validate exported stack data and actively resolve the identified issues.
csdx cm:stacks:audit:fix
Note: The prompt appears only if you have not passed the --copy-dir flag.
You successfully ran an audit operation to fix data issues in your stack.
Alternatively, you can pass the path in the command as given below:
csdx cm:stacks:audit:fix --data-dir <path>csdx cm:stacks:audit:fixor
csdx audit:fixOptions
{
"branch": "<branch-name>"
}{
"fixSelectField": true
}Examples
csdx cm:stacks:audit:fix --copy-dircsdx cm:stacks:audit:fix --report-path <path> --copy-dircsdx cm:stacks:audit:fix --report-path <path> --filter="name=<filter-value>"csdx cm:stacks:audit:fix --report-path <path> --copy-dir --copy-path <path>The Content Types module audits the following:
Report files generated:
content-types.json/content-types.csv
The Global Fields module audits the same issues as the Content Types module, using the same audit logic.
Report files generated:
global-fields.json/global-fields.csv
The Entries module audits the following:
Report files generated:
The Extensions module audits the following:
Report files generated:
extensions.json/extensions.csv
The Workflows module audits the following:
Report files generated:
workflows.json/workflows.csv
The Custom Roles module audits the following:
Report files generated:
custom-roles.json/custom-roles.csv
The Assets module audits the following:
Report files generated:
assets.json/assets.csv
The Field Rules module audits the following:
Report files generated:
field-rules.json / field-rules.csv
A summary report provides an overview of all audited modules.
Report file:
Summary.json/Summary.csv
Summary report structure:
Some modules require other modules to be present in the exported data for proper auditing. Understanding these dependencies helps ensure accurate audit results.
The Entries module requires the following modules to be present in the exported data to perform a complete audit:
Note: If required dependencies are missing, the Entries audit may return incomplete or inaccurate results.
The Assets module requires the following modules to be present in the exported data to perform a complete audit:
The Field Rules module requires the following modules to be present in the exported data to perform a complete audit:
The following modules have no dependencies and can be audited independently:
This section outlines complete workflows for common developer use cases with the Audit plugin.
Validate exported data before importing it into another stack to identify and fix issues early.
Complete Workflow:
# Step 1: Export data from the source stack
csdx cm:stacks:export --data-dir ./exported-data
# Step 2: Audit the exported data
csdx cm:stacks:audit --data-dir ./exported-data --report-path ./audit-reports
# Step 3: Review the Summary report
cat ./audit-reports/Summary.json
# Step 4: If issues are found, fix them
csdx cm:stacks:audit:fix --data-dir ./exported-data --copy-dir --report-path ./audit-reports
# Step 5: Verify fixes by auditing again
csdx cm:stacks:audit --data-dir ./exported-data --report-path ./audit-reports-verify
# Step 6: Import the fixed data
csdx cm:stacks:import --data-dir ./exported-dataAfter exporting, run a quality check on critical modules to ensure data integrity and structural completeness.
Complete Workflow:
# Step 1: Export data
csdx cm:stacks:export --data-dir ./my-export
# Step 2: Run a quick audit (focus on critical modules)
csdx cm:stacks:audit \
--data-dir ./my-export \
--modules=content-types \
--modules=entries \
--modules=assets \
--report-path ./quick-audit
# Step 3: Check for any critical issues in the export
if [ -s ./quick-audit/Summary.json ]; then
echo "Issues found. Review the reports in ./quick-audit"
# Review specific reports
cat ./quick-audit/entries.json
else
echo "Export completed. No issues detected."
fiAutomatically fix all audit-detected issues to prepare your data for a clean migration.
Complete Workflow:
# Step 1: Export data from the source stack
csdx cm:stacks:export --data-dir ./migration-data
# Step 2: Perform a full audit to identify all issues
csdx cm:stacks:audit \
--data-dir ./migration-data \
--report-path ./migration-audit \
--show-console-output
# Step 3: Review which issues can be fixed automatically
cat ./migration-audit/Summary.json | grep -A 5 "Fixable"
# Step 4: Fix all fixable issues with backup
csdx cm:stacks:audit:fix \
--data-dir ./migration-data \
--copy-dir \
--copy-path ./migration-data-backup \
--report-path ./migration-fix-reports
# Step 5: Verify the fixes
csdx cm:stacks:audit \
--data-dir ./migration-data \
--report-path ./migration-verify
# Step 6: Compare results before and after
echo "Before fix:"
cat ./migration-audit/Summary.json
echo "After fix:"
cat ./migration-verify/Summary.jsonRun audits only on specific modules when you want to target known problem areas or speed up the process for large stacks.
Complete Workflow:
# Step 1: Audit only the entries module (recommended for large stacks)
csdx cm:stacks:audit \
--data-dir ./exported-data \
--modules=entries \
--report-path ./entries-audit
# Step 2: If entry issues are found, audit dependent modules
csdx cm:stacks:audit \
--data-dir ./exported-data \
--modules=content-types \
--modules=global-fields \
--report-path ./dependencies-audit
# Step 3: Fix entry-specific issues
csdx cm:stacks:audit:fix \
--data-dir ./exported-data \
--modules=entries \
--copy-dirAudit branch-specific issues before merging or migrating to the main branch.
Complete Workflow:
# Step 1: Export branch data
csdx cm:stacks:export \
--data-dir ./branch-data \
--branch my-feature-branch
# Step 2: Audit branch data (excluding main branch from workflows/roles)
csdx cm:stacks:audit \
--data-dir ./branch-data \
--config branch-config.json \
--report-path ./branch-audit
# Where branch-config.json contains:
# {
# "branch": "main"
# }
# Step 3: Fix issues in the branch data
csdx cm:stacks:audit:fix \
--data-dir ./branch-data \
--config branch-config.json \
--copy-dir
# Step 4: Verify the branch data is clean
csdx cm:stacks:audit \
--data-dir ./branch-data \
--config branch-config.json \
--report-path ./branch-verifyAutomate auditing in your deployment pipeline.
Complete Workflow (GitHub Actions example):
# .github/workflows/audit.yml
name: Audit Exported Data
on: [push, pull_request]
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Export stack data
run: |
csdx cm:stacks:export --data-dir ./exported-data
- name: Run audit
run: |
csdx cm:stacks:audit \
--data-dir ./exported-data \
--report-path ./audit-reports \
--output json
- name: Check for issues
run: |
if [ -s ./audit-reports/Summary.json ]; then
echo "Issues found in exported data!"
cat ./audit-reports/Summary.json
exit 1
else
echo "No issues found. Data is clean!"
fi
- name: Upload audit reports
uses: actions/upload-artifact@v2
if: failure()
with:
name: audit-reports
path: ./audit-reports#!/bin/bash
# audit-check.sh
EXPORT_DIR="./exported-data"
AUDIT_DIR="./audit-reports"
# Export data
csdx cm:stacks:export --data-dir "$EXPORT_DIR"
# Run audit
csdx cm:stacks:audit \
--data-dir "$EXPORT_DIR" \
--report-path "$AUDIT_DIR" \
--output json
# Check if issues were found
if [ -s "$AUDIT_DIR/Summary.json" ]; then
echo "Audit failed: Issues found"
cat "$AUDIT_DIR/Summary.json"
exit 1
else
echo "Audit passed: No issues found"
exit 0
fiAutomatically fix invalid select field values in the entries.
Complete Workflow:
# Step 1: Audit entries to find select field issues
csdx cm:stacks:audit \
--data-dir ./exported-data \
--modules=entries \
--report-path ./audit-reports
# Step 2: Review the select field issues report
cat ./audit-reports/Entries_Select_field.json
# Step 3: Create a configuration file to enable select field fixing
cat > select-fix-config.json << EOF
{
"fixSelectField": true
}
EOF
# Step 4: Fix select field issues using the configuration
csdx cm:stacks:audit:fix \
--data-dir ./exported-data \
--config select-fix-config.json \
--copy-dir \
--report-path ./fix-reports
# Step 5: Verify that select field issues were resolved
csdx cm:stacks:audit \
--data-dir ./exported-data \
--modules=entries \
--report-path ./verify-reports