Back to Directus

Data Operations

content/guides/12.integrations/2.clay/directus-clay-data-operations.md

latest5.9 KB
Original Source

This guide covers advanced techniques for working with Directus data in Clay, including filtering, field selection, pagination, and optimization strategies.

← Back to Directus + Clay Overview

Working with Directus Data

Understanding Filters

When retrieving data from Directus, you can use powerful filter operators to find exactly what you need.

Filter syntax in Clay query parameters:

  • Key: filter[field_name][operator]
  • Value: The comparison value

Common operators:

OperatorDescriptionExample
_eqEqualsfilter[status][_eq]published
_neqNot equalsfilter[status][_neq]draft
_containsContains (case sensitive)filter[title][_contains]Guide
_icontainsContains (case insensitive)filter[title][_icontains]guide
_inIn arrayfilter[status][_in]draft,published
_gtGreater thanfilter[views][_gt]1000
_ltLess thanfilter[price][_lt]100
_nullIs nullfilter[deleted_at][_null]true
_nnullIs not nullfilter[published_at][_nnull]true

Selecting Specific Fields

To improve performance and reduce data transfer, specify only the fields you need:

In query parameters:

  • Key: fields
  • Value: Comma-separated field names (e.g., id,title,status,author)

Including related fields:

  • Use dot notation: author.first_name,author.last_name
  • This pulls in data from related collections

Sorting and Pagination

::field{name="sort" type="string"} Field name (prefix with - for descending). Example: -date_created (newest first) ::

::field{name="limit" type="number"} Maximum items to return (e.g., 50) ::

::field{name="offset" type="number"} Number of items to skip (e.g., 0, 50, 100) ::


Common Use Cases

Use CaseScenarioSteps
🛒 E-commerce Product EnrichmentEnrich product data with inventory and pricing information1. Use Get Item from Collection to check if a product exists in Directus
  1. Use Update Item in Collection to update stock levels from external sources
  2. Use Get Related Item Details to pull supplier information | | 📝 Content Publication Workflow | Automatically publish content when it's approved in Clay | 1. Use Directus webhooks to send draft content to Clay for review
  3. Enrich content with SEO metadata and keyword research in Clay
  4. Use Update Item in Collection to publish content back to Directus | | 👥 Lead Enrichment System | Sync CRM data between Clay and Directus | 1. Use Directus webhooks to send new leads to Clay
  5. Enrich leads with company data and contact information
  6. Use Update Item in Collection to sync enriched data back
  7. Use Get Related Item Details to pull company profiles | | 📋 Form Submission Processing | Process form submissions and create records | 1. Use Directus webhooks to send form submissions to Clay
  8. Use Get Item from Collection to check for existing records
  9. Use Create Item in Collection to add new contacts
  10. Use Update Item in Collection to update existing records |

Troubleshooting

When working with Directus API through Clay, you may encounter various error codes. For a comprehensive list of Directus error codes and their meanings, refer to the official Directus Error Codes documentation.

Common Issues

Authentication Problems:

  • Verify your API token is valid and active
  • Check that you're using the correct format: Bearer YOUR_TOKEN
  • Ensure the token hasn't expired

Collection and Field Issues:

  • Verify collection names match exactly (case-sensitive)
  • Check that field names match your Directus schema
  • Ensure proper permissions are set for collections

Filter and Query Issues:

  • Use the correct format: filter[field][operator]
  • Test filters in Directus admin panel first
  • Check for special characters that need escaping

Getting Help

If you encounter issues:

  1. For Directus-specific questions: Ask for help in the Directus Community
  2. For Clay-specific questions: Contact Clay support or check Clay's documentation
  3. For API connection issues: Verify your Directus configuration and permissions

Next Steps

Additional Resources