Docs/API REFERENCE/Get your API key

Get your API key

Your API key allows you to programmatically access your VersaTailor analytics data. This guide will show you how to obtain and configure your API key.

Prerequisites

Before you can get your API key, you need:

  • A VersaTailor account
  • At least one website added to your account
  • Admin access to the website

Step 1: Navigate to Website Settings

  1. Go to your dashboard and select your website
  2. Click on the dropdown menu for your website in the top left of your dashboard
  3. Click on "Site Settings"

Site Settings screenshot

Step 2: Generate API Key

  1. Under "API" tab, you'll be able to generate your API key for that website
  2. Be sure to copy it immediately as we won't be able to show it to you again for security reasons
  3. Do NOT commit this key to source control and keep it safe

Get API Key from API Settings

Step 3: Configure Environment Variables

Add your API key to your environment variables:

# .env.local
VERSATAILOR_API_KEY=your_api_key_here
VERSATAILOR_WEBSITE_ID=your_website_id_here

Using Your API Key

Basic Authentication

Include your API key in the Authorization header:

const response = await fetch("https://versatailor.com/api/v1/realtime", {
  headers: {
    Authorization: `Bearer ${process.env.VERSATAILOR_API_KEY}`,
    "Content-Type": "application/json",
  },
});

Example: Fetching Real-time Data

async function getRealtimeVisitors() {
  const response = await fetch("https://versatailor.com/api/v1/realtime", {
    headers: {
      Authorization: `Bearer ${process.env.VERSATAILOR_API_KEY}`,
      "Content-Type": "application/json",
    },
  });

  const data = await response.json();
  return data;
}

Security Best Practices

  • Never commit API keys to version control
  • Use environment variables for storing API keys
  • Rotate API keys regularly for enhanced security
  • Limit API key access to only necessary team members
  • Monitor API usage for unusual activity

API Key Permissions

Your API key has the following permissions:

  • Read access to analytics data
  • Read access to real-time visitor data
  • Read access to custom events
  • Read access to revenue data (if enabled)

Troubleshooting

Invalid API Key Error

If you receive an "Invalid API Key" error:

  1. Verify the API key is correct
  2. Check that the key hasn't expired
  3. Ensure you're using the correct website ID
  4. Contact support if the issue persists

Rate Limiting

API requests are rate-limited to prevent abuse:

  • Free plans: 100 requests per hour
  • Pro plans: 1,000 requests per hour
  • Enterprise plans: 10,000 requests per hour

Next Steps

Now that you have your API key, you can:

Need help? Contact us for assistance.

Suggest features? We'd love your feedback