#!/bin/bash # Configuration API_URL="http://localhost:8059" EMAIL="marc@mintel.me" PASSWORD="Tim300493." echo "Logging in to Directus..." TOKEN=$(curl -s -X POST "${API_URL}/auth/login" \ -H "Content-Type: application/json" \ -d "{\"email\":\"${EMAIL}\", \"password\":\"${PASSWORD}\"}" | grep -o '"access_token":"[^"]*' | cut -d'"' -f4) if [ -z "$TOKEN" ]; then echo "Login failed!" exit 1 fi echo "Hiding 'leads' collection..." curl -s -X PATCH "${API_URL}/collections/leads" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d '{"meta": {"hidden": true}}' echo "Creating 'people' collection..." curl -s -X POST "${API_URL}/collections" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "collection": "people", "schema": {}, "meta": { "icon": "person", "display_template": "{{first_name}} {{last_name}}", "show_status_indicator": true } }' echo "Adding fields to 'people'..." FIELDS='[ {"field": "first_name", "type": "string", "meta": {"interface": "input", "width": "half"}}, {"field": "last_name", "type": "string", "meta": {"interface": "input", "width": "half"}}, {"field": "email", "type": "string", "meta": {"interface": "input", "width": "half"}}, {"field": "phone", "type": "string", "meta": {"interface": "input", "width": "half"}}, {"field": "company", "type": "string", "meta": {"interface": "input", "width": "full"}} ]' for field in $(echo "${FIELDS}" | jq -c '.[]'); do curl -s -X POST "${API_URL}/fields/people" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d "${field}" done echo "Adding 'contact_person' to 'leads', 'client_users', and 'visual_feedback'..." for collection in leads client_users visual_feedback; do curl -s -X POST "${API_URL}/fields/${collection}" \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "field": "contact_person", "type": "uuid", "meta": { "interface": "select-dropdown-m2o", "options": { "template": "{{first_name}} {{last_name}}" } }, "schema": { "foreign_key_column": "id", "foreign_key_table": "people" } }' done echo "Done!"