Skip to main content
Strapi

Learn how to integrate ApiTraffic with a Strapi application

Dustin Lewis avatar
Written by Dustin Lewis
Updated over 2 months ago

Install the SDK

Install ApiTraffic for Strapi via NPM. Run the following command:

npm i @apitraffic/strapi

IMPORTANT: Node 18+ required.

Once the package is installed, the middleware must be added to the config/middlewares.js file:

module.exports = [
//...
'plugin::apitraffic.apitraffic',
]

Getting Started

Ensure you have already created a trial or paid account at apitraffic.io to get your API Token and Bucket ID. These variables can either be added to the .env file or set in the same way other environment variables are being set. The full list of configuration options can be found below. In this example we will use the function parameter option.

API_TRAFFIC_TOKEN=[your-ingest-token]
API_TRAFFIC_BUCKET=[your-bucket-id]

That is it! Your inbound (and outbound) API requests will now be sent to the ApiTraffic servers for logging. Additionally, powerful workflows can now be setup to take action on matching requests.

Environment Variables

Example of setting the required variables as environment variables:

export API_TRAFFIC_TOKEN=[your-ingest-token]
export API_TRAFFIC_BUCKET=[your-bucket-id]

Configuration Options

These methods are not mutually exclusive, if for whatever reason you need to set some as parameters and some as environment variables, it is ok they can be mixed.

If the same variable is set in both places, the parameters that are passed in will always supersede the environment variables.

Ingestion Token

This is a required parameter that authenticates your API with the requests to ApiTraffic. It is important that the token type is set as ingest when setting up your token in ApiTraffic, regular integration tokens will not work for sending traffic to the ingestion endpoint.

Environment Variable: API_TRAFFIC_TOKEN

Bucket ID

This is a required parameter that indicates what bucket the data should be stored in. Buckets allow for more granular data segmentation.

Environment Variable: API_TRAFFIC_BUCKET

Did this answer your question?