Authentication
Learn how to authenticate your API requests with Time4Boost.
Authentication Overview
Time4Boost uses a two-factor authentication system to ensure secure access to the API.
To authenticate your requests, you need to provide two pieces of information:
- An API Key: This identifies your account and determines your access level.
- An Authorization Token: This verifies your current session and user status.
API Keys
API keys are unique identifiers for your account and determine your access level and rate limits.
You can obtain an API key by creating a free account on our website. Once logged in, navigate to your dashboard to generate and manage your API keys.
Include your API key in all API requests to the server in a header that looks like this:
X-API-Key: YOUR_API_KEY
Authorization Tokens
Authorization tokens are temporary credentials that verify your current session and user status.
You need to include an Authorization token in your requests. This token is obtained when you log in to your account and should be refreshed periodically.
Include the Authorization token in the header of your requests like this:
Authorization: Bearer YOUR_AUTH_TOKEN
Code Examples
Here are examples of how to make authenticated requests in various languages:
JavaScript (Node.js)
const fetch = require('node-fetch');
const apiKey = 'YOUR_API_KEY';
const authToken = 'YOUR_AUTH_TOKEN';
async function makeApiRequest() {
const response = await fetch('https://api.time4boost.com/v1/nba/teams', {
headers: {
'X-API-Key': apiKey,
'Authorization': `Bearer ${authToken}`,
},
});
const data = await response.json();
console.log(data);
}
makeApiRequest();
Python
import requests
api_key = 'YOUR_API_KEY'
auth_token = 'YOUR_AUTH_TOKEN'
headers = {
'X-API-Key': api_key,
'Authorization': f'Bearer {auth_token}',
}
response = requests.get('https://api.time4boost.com/v1/nba/teams', headers=headers)
data = response.json()
print(data)
cURL
curl -X GET 'https://api.time4boost.com/v1/nba/teams' -H 'X-API-Key: YOUR_API_KEY' -H 'Authorization: Bearer YOUR_AUTH_TOKEN'
Tier Restrictions
Access to API endpoints is restricted based on your account tier:
- Free and Trial tiers: Limited access to Teams, Players, and Games endpoints
- Basic tier: Access to Teams, Players, Games, Player Stats, Active Players, Player Injuries, and Season Averages endpoints
- Pro and higher tiers: Full access to all endpoints
Error Handling
Understanding authentication-related errors and how to resolve them.
If your authentication fails, you may receive one of the following error responses:
- 401 Unauthorized: This error occurs when either your API key or Authorization token is invalid or missing. Double-check that you've included both headers correctly.
- 403 Forbidden: This error suggests that your API key is valid, but you don't have permission to access the requested resource. Check your account's access level and ensure you're using the correct API key for the desired tier.
Security Best Practices
Keeping your API key and Authorization token secure.
- Never share your API key or Authorization token publicly or commit them to version control.
- Use environment variables or secure secret management systems to store your credentials.
- Rotate your API keys periodically, especially if you suspect they may have been compromised.
- Implement proper error handling in your applications to avoid exposing sensitive information in error messages.