API
Authentication

API Authentication

All requests to the Trycolors API must be authenticated using an API key. This ensures that only authorized users can access the API and helps us maintain the security and integrity of our service.

Obtaining an API Key

To get an API key:

  1. Sign in to your Trycolors account at trycolors.com/signin (opens in a new tab).
  2. Go to your account settings at trycolors.com/user/settings (opens in a new tab).
  3. Find the "API Keys" card.
  4. Click "Generate API Key".
  5. Copy and securely store your new API key.

Using Your API Key

To authenticate your requests, include your API key in the X-API-KEY header of each request:

X-API-KEY: your_api_key_here

A request with no key returns 401 with the plain-text body Authentication required: X-API-KEY or X-Session-ID header. A request with a key we do not recognise returns 401 with Invalid API Key. Both bodies are plain text, not JSON, so do not parse them as JSON.

Example Request

Here's an example of how to include your API key in a request using JavaScript and fetch:

const apiKey = 'your_api_key_here';
const endpoint = 'https://api.trycolors.com/v1/mix-colors';
 
fetch(endpoint, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': apiKey
  },
  body: JSON.stringify({
    // request payload
  })
})
.then(response => {
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  }
  return response.json();
})
.then(data => {
  console.log(data);
})
.catch(error => {
  console.error('Error:', error.message);
});

Security Best Practices

  1. Never share your API key publicly or commit it to version control systems.
  2. Use environment variables or secure secret management systems to store your API key.
  3. Rotate your API key periodically for enhanced security.
  4. If you suspect your API key has been compromised, generate a new one and delete the old one from your settings page. Deleting a key takes effect within two minutes, because key lookups are cached that long.

For any issues with authentication, please contact our support team (opens in a new tab).