Authentication overview
The TVMaze API provides access to a comprehensive database of TV shows, episodes, and cast information. Unlike many APIs that require explicit API keys or tokens for basic access, TVMaze primarily relies on IP-based rate limiting for non-commercial, read-only usage. This design simplifies initial integration for developers building personal media organizers, small applications, or fan communities, as it removes the need for credential management in these scenarios.
For operations beyond standard read-only access, such as commercial applications or those requiring higher request volumes, TVMaze outlines a different approach. Developers seeking to use the API for commercial purposes or to exceed the public rate limits are instructed to contact TVMaze directly to discuss specific licensing agreements. These agreements may involve custom authentication mechanisms tailored to the commercial use case, which could include API keys, tokens, or other proprietary methods not publicly documented for the free tier.
It is crucial for developers to understand the distinction between the free, non-commercial tier and commercial usage. Adhering to the terms of service, including respecting rate limits and obtaining appropriate licenses for commercial applications, is a foundational aspect of using the TVMaze API responsibly. All interactions with the API should occur over secure channels (HTTPS) to protect data integrity and user privacy.
Supported authentication methods
TVMaze offers a streamlined approach to authentication, primarily distinguishing between non-commercial and commercial use cases. The methods supported reflect this distinction, prioritizing ease of access for hobbyist developers while reserving more explicit authentication for licensed applications.
| Method | When to Use | Security Level |
|---|---|---|
| IP-based Rate Limiting | Non-commercial projects, personal use, read-only data access within documented rate limits. | Minimal (relies on source IP for rate control, not user identity). |
| Custom/Proprietary (via Licensing Agreement) | Commercial applications, high-volume data access, specific use cases requiring enhanced security or exceeding standard rate limits. | Determined by specific licensing terms; may include API keys, OAuth 2.0, or other mechanisms. |
For the non-commercial tier, the API's design means that the primary 'authentication' mechanism is implicitly tied to the source IP address making the request. This method is effective for preventing abuse and ensuring fair usage across the public API but does not provide user-level authentication or authorization. For scenarios where user identity or specific application authorization is required, developers would typically implement their own user management systems separate from the TVMaze API access.
The absence of public API keys for the default tier simplifies the initial development process, as there's no need to manage client secrets or implement token refresh flows. However, this also places a greater responsibility on the developer to design their application securely, particularly concerning data received from the API and any user-specific data they may manage.
Getting your credentials
For most non-commercial use cases, explicit credentials in the form of API keys or tokens are not required to access the TVMaze API. Your application's requests are identified and rate-limited based on its public IP address. This means that to get started, you simply need to begin making requests to the TVMaze API endpoints.
However, if your project is commercial in nature, requires higher rate limits than those publicly documented, or involves specific licensing terms, obtaining credentials will involve a direct engagement with TVMaze. The process is as follows:
- Evaluate your usage: Determine if your application falls under TVMaze's definition of commercial use or if your anticipated request volume will exceed the free tier's rate limits.
- Contact TVMaze: Reach out to TVMaze's team to discuss your specific requirements and potential licensing agreements. This typically involves describing your application, its purpose, and your anticipated data usage.
- Negotiate terms: Based on your needs, TVMaze will outline licensing options. These agreements may include provisions for custom authentication methods, such as dedicated API keys, which would then be provided to you upon agreement.
- Receive custom credentials: If a licensing agreement is established, TVMaze will provide you with the necessary credentials and instructions for their use, which will be specific to your commercial license.
It's important to note that the specifics of commercial credentials are not publicly documented and are handled on a case-by-case basis through direct communication with TVMaze. This approach ensures that commercial users receive tailored support and appropriate access levels for their specific business models.
For developers who require authentication mechanisms for their own users within an application that integrates with TVMaze, standard practices such as OAuth 2.0 or API key management for internal services would be implemented independently of the TVMaze API's direct authentication requirements.
Authenticated request example
Since the TVMaze API does not typically require API keys or tokens for its standard, non-commercial read-only endpoints, an "authenticated" request is effectively any well-formed request made over HTTPS. The authentication mechanism in this context is the implicit trust established by the source IP address for rate limiting purposes. Below is an example of a basic request to retrieve information about a TV show, demonstrating the lack of explicit credential headers:
curl -X GET \
'https://api.tvmaze.com/singlesearch/shows?q=game%20of%20thrones' \
-H 'Accept: application/json'
In this example:
curl -X GET: Specifies an HTTP GET request.'https://api.tvmaze.com/singlesearch/shows?q=game%20of%20thrones': This is the API endpoint being accessed. The query parameterq=game%20of%20thronesspecifies the search term.-H 'Accept: application/json': Sets theAcceptheader, indicating that the client prefers a JSON response.
For commercial licenses where custom authentication, such as an API key, might be provided, the request structure would adapt to include these credentials, typically in an HTTP header or as a query parameter, depending on the agreed-upon mechanism. For instance, if a hypothetical API key (YOUR_API_KEY) were provided, a request might look like this:
curl -X GET \
'https://api.tvmaze.com/singlesearch/shows?q=game%20of%20thrones' \
-H 'Accept: application/json' \
-H 'X-API-Key: YOUR_API_KEY' # Example for custom authentication
Developers should always consult their specific licensing agreement for the exact method of including any provided credentials. Without such an agreement, the simpler, non-credentialed request is the standard practice for the public API.
Security best practices
Although the TVMaze API simplifies access by not requiring explicit API keys for public use, adhering to security best practices remains essential for any application integrating with it. These practices ensure the integrity of your application, protect user data, and maintain a good relationship with the API provider.
- Always Use HTTPS/TLS: All communication with the TVMaze API should occur over HTTPS (TLS). This encrypts the data in transit, protecting it from eavesdropping and tampering. The Transport Layer Security (TLS) protocol is the successor to SSL and is critical for secure web communication.
- Respect Rate Limits: Be mindful of the documented rate limits for the TVMaze API. Exceeding these limits can lead to temporary or permanent IP bans. Implement client-side rate limiting or caching mechanisms to reduce the number of requests made to the API, thereby preventing service interruptions and ensuring fair usage.
- Implement Robust Error Handling: Design your application to gracefully handle API errors, including rate limit errors (e.g., HTTP 429 Too Many Requests). Implement exponential backoff and retry logic for transient errors to avoid overwhelming the API.
- Data Validation and Sanitization: Any data retrieved from the TVMaze API should be validated and sanitized before being displayed to users or stored in your database. This prevents common vulnerabilities like cross-site scripting (XSS) if the data is rendered in a web interface.
- Client-Side Security (for web apps): If you are building a web application, ensure proper client-side security measures. This includes Content Security Policy (CSP) to mitigate XSS attacks and secure cookie practices if you are managing user sessions.
- Secure Storage of Commercial Credentials: If you have a commercial license and receive API keys or other credentials, store them securely. Never hardcode credentials directly into your application's source code. Use environment variables, secure configuration files, or dedicated secret management services (e.g., AWS Secrets Manager, Azure Key Vault, Google Secret Manager) to manage sensitive information.
- Regular Security Audits: Periodically review your application's security posture. Check for outdated dependencies, misconfigurations, and potential vulnerabilities, especially if you manage user data or integrate with other services.
- Adhere to Licensing Agreements: For commercial users, strictly adhere to the terms of your licensing agreement with TVMaze. This includes any specific security requirements or usage policies outlined in the agreement.