> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apitraffic.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Strapi

> Monitor your Strapi CMS APIs with ApiTraffic

## Installation

Install the Strapi integration package:

<CodeGroup>
  ```bash npm theme={null}
  npm install @apitraffic/strapi
  ```

  ```bash yarn theme={null}
  yarn add @apitraffic/strapi
  ```

  ```bash pnpm theme={null}
  pnpm add @apitraffic/strapi
  ```
</CodeGroup>

<Note>
  **Node 18+ required**
</Note>

## Setup

### 1. Install the Plugin

Add the ApiTraffic plugin to your Strapi application:

```bash theme={null}
npm install @apitraffic/strapi --save
```

### 2. Add to Middlewares Configuration

The middleware must be added to the `config/middlewares.js` file:

```javascript theme={null}
module.exports = [
  'strapi::logger',
  'strapi::errors',
  'strapi::security',
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::query',
  'strapi::body',
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
  // Add ApiTraffic middleware
  'plugin::apitraffic.apitraffic',
];
```

### 3. Environment Configuration

Add the required environment variables to your `.env` file:

```bash .env theme={null}
API_TRAFFIC_TOKEN=your-api-token
API_TRAFFIC_BUCKET=your-bucket-id
```

## Configuration

### Required Environment Variables

| Environment Variable | Required | Type   | Description                               |
| -------------------- | -------- | ------ | ----------------------------------------- |
| `API_TRAFFIC_TOKEN`  | Yes      | String | Ingest token from your ApiTraffic account |
| `API_TRAFFIC_BUCKET` | Yes      | String | Bucket ID for data organization           |

### Optional Configuration

You can also configure additional options by creating a plugin configuration file at `config/plugins.js`:

```javascript theme={null}
module.exports = {
  'apitraffic': {
    enabled: true,
    config: {
      token: process.env.API_TRAFFIC_TOKEN,
      bucket: process.env.API_TRAFFIC_BUCKET,
      interceptOutbound: true,
      debug: false
    }
  }
};
```

## Features

### Automatic API Monitoring

Once installed, ApiTraffic automatically monitors:

* **Content API requests** - All requests to your Strapi content endpoints
* **Admin API requests** - Administrative operations and user management
* **Custom API routes** - Any custom routes you've added to your Strapi application
* **Plugin API calls** - Requests to installed plugin endpoints

### Workflow Integration

ApiTraffic's workflow engine allows you to create automated workflows that trigger based on your Strapi API activity:

* **Content Creation Workflows** - Trigger actions when new content is created
* **User Registration Flows** - Automate user onboarding processes
* **Data Synchronization** - Sync content changes with external systems
* **Notification Systems** - Send alerts based on API usage patterns

### Real-time Analytics

Monitor your Strapi application with comprehensive analytics:

* Request volume and patterns
* Response times and performance metrics
* Error rates and debugging information
* User activity and content usage statistics

## Security Features

### Data Redaction

ApiTraffic automatically redacts sensitive data based on your account settings. Configure redaction rules in your ApiTraffic dashboard to protect:

* User passwords and authentication tokens
* Personal identifiable information (PII)
* Payment and financial data
* Custom sensitive fields

### Request Exclusions

Exclude specific endpoints from monitoring by configuring exclusion rules in your ApiTraffic account. Common exclusions for Strapi include:

* Health check endpoints (`/_health`)
* Static asset requests
* Admin panel assets
* Internal monitoring endpoints

## Advanced Usage

### Custom Tagging

While Strapi doesn't support direct tagging in middleware, you can add custom tags through controller extensions:

```javascript theme={null}
// In your custom controller
module.exports = {
  async find(ctx) {
    // Add custom context through Strapi's built-in logging
    strapi.log.info('Custom operation', {
      userId: ctx.state.user?.id,
      contentType: 'articles'
    });
    
    return await super.find(ctx);
  }
};
```

### Webhook Integration

Combine ApiTraffic with Strapi webhooks for comprehensive monitoring:

```javascript theme={null}
// config/plugins.js
module.exports = {
  'apitraffic': {
    enabled: true,
    config: {
      token: process.env.API_TRAFFIC_TOKEN,
      bucket: process.env.API_TRAFFIC_BUCKET
    }
  },
  'webhooks': {
    enabled: true,
    config: {
      // Configure webhooks to work alongside ApiTraffic
    }
  }
};
```

## Troubleshooting

<AccordionGroup>
  <Accordion title="Plugin not capturing requests">
    Ensure the ApiTraffic middleware is properly added to your `config/middlewares.js` file and placed in the correct order.
  </Accordion>

  <Accordion title="Missing environment variables">
    Verify that `API_TRAFFIC_TOKEN` and `API_TRAFFIC_BUCKET` are set in your `.env` file and that Strapi is loading them correctly.
  </Accordion>

  <Accordion title="Plugin not loading">
    Check that the plugin is properly installed and that your `package.json` includes `@apitraffic/strapi` in dependencies.
  </Accordion>

  <Accordion title="Performance issues">
    If you're experiencing performance issues, consider adjusting the sampling rate in your ApiTraffic account settings.
  </Accordion>
</AccordionGroup>

### Debug Mode

Enable debug logging by setting the debug flag in your plugin configuration:

```javascript theme={null}
// config/plugins.js
module.exports = {
  'apitraffic': {
    enabled: true,
    config: {
      token: process.env.API_TRAFFIC_TOKEN,
      bucket: process.env.API_TRAFFIC_BUCKET,
      debug: true
    }
  }
};
```

## Strapi Marketplace

The ApiTraffic plugin is available on the [Strapi Marketplace](https://market.strapi.io/plugins/@apitraffic-strapi) for easy discovery and installation.

## Use Cases

### Content Management Monitoring

* Track content creation, updates, and deletions
* Monitor user engagement with different content types
* Analyze API usage patterns for optimization

### Performance Optimization

* Identify slow-performing endpoints
* Monitor database query performance
* Track memory and CPU usage patterns

### Security Monitoring

* Detect unusual API access patterns
* Monitor authentication failures
* Track admin panel usage

### Integration Workflows

* Automatically sync content with external systems
* Trigger email campaigns based on content changes
* Update search indexes when content is modified

## Next Steps

<CardGroup cols={2}>
  <Card title="Dashboard" icon="chart-line" href="https://app.apitraffic.io">
    View your Strapi API traffic data and analytics
  </Card>

  <Card title="Workflow Engine" icon="workflow" href="https://docs.apitraffic.io/workflow-engine">
    Create automated workflows based on your Strapi data
  </Card>

  <Card title="Strapi Marketplace" icon="store" href="https://market.strapi.io/plugins/@apitraffic-strapi">
    View the plugin on Strapi Marketplace
  </Card>

  <Card title="Sample Applications" icon="code" href="https://github.com/apitraffic/apitraffic-strapi">
    Explore example implementations
  </Card>
</CardGroup>
