Directus Cheat Sheet




Extract and Apply CLI 

//template structure (schema, permissions, content, files, flows, relations.json

npx directus-template-cli@latest extract -p `

  --directusUrl="$env:SOURCE_DIRECTUS_URL" `

  --directusToken="$env:SOURCE_DIRECTUS_TOKEN" `

  --templateLocation="./prj-template" `

  --templateName="prj-dev-$(Get-Date -Format yyyyMMdd-HHmm)"


  npx directus-template-cli@latest apply -p `

  --directusUrl="$env:TARGET_DIRECTUS_URL" `

  --directusToken="$env:TARGET_DIRECTUS_TOKEN" `

  --templateLocation="./prj-template" `

  --templateType="local" `

  --partial `

  --files `

  --permissions `

  --content `

  --users `

  --flows `

  --settings `

  --dashboards `

  --extensions


Apply CLI Command


npx directus-template-cli@latest apply -p `

  --directusUrl="$env:TARGET_DIRECTUS_URL" `

  --directusToken="$env:TARGET_DIRECTUS_TOKEN" `

  --templateLocation="./prj-template" `

  --templateType="local" `

  --schema `

  --content `

  --flows `

  --settings `

  --users `

  --files `

  --permissions



Upload File in CMS


  curl -X POST "https://cmsuat.prj.sgjourney.gov.sg/files" \

  -H "Authorization: Bearer Ca1WntygNscU_zJXRF1IJxkfzmjWz-UE" \

  -F "file=@C:\Users\2314638\Downloads\Log to console.jpg" \

  -F "title=User avatar" \

  -F "folder=e6308546-92fb-4b10-b586-eefaf1d97f7f" \

  -F "private=false"


Apply CLI working:


//apply working:

npx directus-template-cli@latest apply -p --directusUrl "$env:TARGET_DIRECTUS_URL" --directusToken "$env:TARGET_DIRECTUS_TOKEN" --templateLocation "./prj-template" --templateName "prj-<YYYYMMDD-HHMM_FROM_EXTRACT>" --schema --content --flows --settings --users --files --permissions --disableTelemetry


Apply CLI


npx directus-template-cli@latest apply -p `

  --directusUrl="$env:TARGET_DIRECTUS_URL" `

  --directusToken="$env:TARGET_DIRECTUS_TOKEN" `

  --templateLocation="./prj-template" `

  --templateType="local" `

  --partial --files `

  --permissions `

  --no-schema --no-content --no-dashboards --no-extensions --no-flows --no-settings --no-users


Download all from UAT-working:



//Downlaod all from UAT-working:


  npx directus-template-cli@latest extract -p --directusUrl "$env:TARGET_DIRECTUS_URL" --directusToken "$env:TARGET_DIRECTUS_TOKEN" --templateLocation "./prj-uat-template" --templateName "prj-uat-$(Get-Date -Format yyyyMMdd-HHmm)" --disableTelemetry


    npx directus-template-cli@latest extract -p --directusUrl "$env:SOURCE_DIRECTUS_URL" --directusToken "$env:SOURCE_DIRECTUS_TOKEN" --templateLocation "./prj-template" --templateName "prj-$(Get-Date -Format yyyyMMdd-HHmm)" --disableTelemetry



OPTICAL CMS CLI


--OPTICAL CMS CLI--


$env:SOURCE_DIRECTUS_URL = "https://cmsdev.prj.sgjourney.gov.sg"

$env:SOURCE_DIRECTUS_TOKEN = "oy9VceiWJsp6LxjhhYsJvAj7d_avMeYZ"

$env:TARGET_DIRECTUS_URL = "https://cmsuat.prj.sgjourney.gov.sg"

$env:TARGET_DIRECTUS_TOKEN = "Ca1WntygNscU_zJXRF1IJxkfzmjWz-UE"


$env:NODE_TLS_REJECT_UNAUTHORIZED="0"


npx directus-template-cli@latest extract -p `

  --directusUrl="$env:SOURCE_DIRECTUS_URL" `

  --directusToken="$env:SOURCE_DIRECTUS_TOKEN" `

  --templateLocation="./prj-template" `

  --templateName="prj-dev-$(Get-Date -Format yyyyMMdd-HHmm)"

  --schema \

  --content \

  --flows \

  --settings \

  --users \

  --files \

  --permissions \

  --relations


Hide Cube icon in CSO view


/* A) Only CSO Search View present — DON'T hide if a folder icon exists in the nav */

#directus

:not(:has(aside#navigation i[data-icon="folder"]))

:has(.module-nav-content .v-list .v-list-group)

:has(.module-nav-content a.v-list-item[href="/admin/content/cso_search_view"])

:not(:has(.module-nav-content a.v-list-item.link:not([href="/admin/content/cso_search_view"])))

  .modules > div.v-button:first-of-type {

  display: none !important;

}


/* B) Only Search present — DON'T hide if a folder icon exists in the nav */

#directus

:not(:has(aside#navigation i[data-icon="folder"]))

:has(.module-nav-content a.v-list-item[href="/admin/global-search"])

:not(:has(.module-nav-content a.v-list-item.link:not([href="/admin/global-search"])))

  .modules > div.v-button:first-of-type {

  display: none !important;

}


-----------------------Local to BCA POC stg - directus-template-cli--------------------------------------------------------


LOCAL_URL = http://localhost:8055 LOCAL_TOKEN = 'mnZGcQ6seIRPXViGNN2nWy1lEeG__Yms' STG_URL = https://cms.bcapoc.staging.optical.gov.sg STG_TOKEN = 'PHm1sUGPcGimQi3iurxW2wRLKi3Wgmkt'




C:\Users\2314638\Downloads\OPTICAL LOCAL SETUP\bca-poc-template> C:\Users\2314638\Downloads\OPTICAL LOCAL SETUP\bca-poc-template> C:\Users\2314638\Downloads\OPTICAL LOCAL SETUP\bca-poc-template> C:\Users\2314638\Downloads\OPTICAL LOCAL SETUP\bca-poc-template>npx directus-template-cli@latest extract -p --templateName="bca-poc" --templateLocation="./bca-poc" --directusUrl="http://localhost:8055" --directusToken="mnZGcQ6seIRPXViGNN2nWy1lEeG__Yms" -- Logged in as Admin User ------------------ Attempting to create directory at: ./bca-poc/src Extracting schema snapshot... done Extracting collections... done Extracting fields... done Extracting relations... done Extracting folders... done Extracting files... done Extracting users... done Extracting roles... done Extracting permissions... done Extracting policies... done Extracting access... done Extracting presets... done Extracting translations... done Extracting flows... done Extracting operations... done Extracting dashboards... done Extracting panels... done Extracting settings... done Extracting extensions... done Extracting content... done Downloading assets... done » Warning: PostHog Error: PostHogFetchNetworkError: Network error while fetching PostHog Error while flushing PostHog PostHogFetchNetworkError: Network error while fetching PostHog at retriable (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:2835:23) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async retriable (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:1601:25) at async PostHog.fetchWithRetry (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:2825:16) at async PostHog._flush (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:2786:17) { error: TypeError: fetch failed at node:internal/deps/undici/undici:13502:13 at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async retriable (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:2828:23) at async retriable (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:1601:25) at async PostHog.fetchWithRetry (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:2825:16) at async PostHog._flush (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:2786:17) { [cause]: Error: self-signed certificate in certificate chain at TLSSocket.onConnectSecure (node:_tls_wrap:1679:34) at TLSSocket.emit (node:events:518:28) at TLSSocket._finishInit (node:_tls_wrap:1078:8) at ssl.onhandshakedone (node:_tls_wrap:864:12) { code: 'SELF_SIGNED_CERT_IN_CHAIN' } }, [cause]: TypeError: fetch failed at node:internal/deps/undici/undici:13502:13 at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async retriable (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:2828:23) at async retriable (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:1601:25) at async PostHog.fetchWithRetry (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:2825:16) at async PostHog._flush (file:///C:/Users/2314638/AppData/Local/npm-cache/_npx/623fa71c079d6ec8/node_modules/posthog-node/lib/node/index.mjs:2786:17) { [cause]: Error: self-signed certificate in certificate chain at TLSSocket.onConnectSecure (node:_tls_wrap:1679:34) at TLSSocket.emit (node:events:518:28) at TLSSocket._finishInit (node:_tls_wrap:1078:8) at ssl.onhandshakedone (node:_tls_wrap:864:12) { code: 'SELF_SIGNED_CERT_IN_CHAIN' } } } | ! You REQUIRE a license to use Directus if your organization has more than $5MM USD a year in revenue and/or funding. | • For all organizations with less than $5MM USD a year in revenue and funding, Directus is free for personal projects, hobby projects and in production. This second group does not require a license. Directus is licensed under BSL 1.1. | • Visit https://directus.io/bsl for more information or reach out to us at licensing@directus.io. ------------------ Template extracted successfully. C:\Users\2314638\Downloads\OPTICAL LOCAL SETUP\bca-poc-template>



Default API permission access:





Comments