Authentication overview

Authentication for the Typeform API ensures that only authorized applications and users can access and manipulate Typeform resources, such as forms, responses, and workspaces. The API uses a token-based authentication system, which is a common approach in modern web APIs, often built on principles outlined in the OAuth 2.0 framework. This method provides a secure and stateless way to verify the identity of the client making a request without requiring the server to store session information.

When an application sends a request to the Typeform API, it includes an authentication credential, typically a Personal Access Token (PAT), in the request header. The API then validates this token. If the token is valid and has the necessary permissions, the request is processed. If the token is invalid, expired, or lacks sufficient scope, the API rejects the request, usually with an HTTP 401 Unauthorized status code.

Typeform's approach to authentication simplifies integration for developers by providing a single, long-lived token for programmatic access. This is particularly useful for server-side applications, scripts, and integrations that need consistent access to Typeform data without requiring repeated user interaction for authentication.

Supported authentication methods

The Typeform API primarily supports authentication via Personal Access Tokens (PATs). These tokens act as bearer tokens, meaning that whoever possesses the token can use it to access the API, similar to how a key grants access to a locked door. Developers generate these tokens from their Typeform account settings, and they are associated with the user account that created them, inheriting that user's permissions within Typeform.

Personal Access Tokens (PATs)

  • Mechanism: PATs are generated through the Typeform developer console. They are long-lived tokens that grant access to your Typeform account's resources. When making an API request, the PAT is included in the Authorization header as a Bearer token.
  • When to Use: Ideal for server-side applications, scripts, integrations, and command-line tools that need to interact with the Typeform API without user interaction. This includes automating form creation, retrieving response data, or managing workspaces.
  • Security Considerations: PATs should be treated with the same level of security as a password. They grant broad access to your Typeform account. Compromised PATs can lead to unauthorized access to your data.

While Typeform API leverages concepts from OAuth 2.0 for token generation, direct OAuth 2.0 flows (like Authorization Code or Client Credentials) for third-party applications are not explicitly detailed as primary developer authentication methods in the same way PATs are for personal integrations. For most direct integrations and programmatic access, developers will utilize PATs.

Authentication Method Comparison

Method When to Use Security Level
Personal Access Token (PAT) Server-side applications, scripts, direct integrations, personal tools requiring programmatic access to Typeform resources. High (if managed securely); direct access to account resources.

Getting your credentials

To authenticate with the Typeform API, you need to generate a Personal Access Token (PAT) from your Typeform account. This token serves as your API key and grants your application the necessary permissions to interact with your Typeform data.

Steps to generate a Personal Access Token:

  1. Log in to Typeform: Access your Typeform account through the web interface.
  2. Navigate to Developer Settings: Go to your account settings. Look for a section related to 'Personal tokens' or 'Developer settings'. The specific path might be Settings > Personal tokens or similar, as detailed in the Typeform API Getting Started guide.
  3. Create a New Token: Click on the option to create a new token. You may be prompted to give your token a descriptive name, which helps in identifying its purpose later.
  4. Define Scopes (if applicable): Depending on the Typeform API's current implementation, you might be able to define specific scopes or permissions for your token. This limits the token's access to only the necessary API endpoints and actions (e.g., read-only access to responses, or full access to forms). Always follow the principle of least privilege, granting only the permissions required for your application's functionality.
  5. Copy the Token: Once generated, the token will be displayed. This is the only time you will see the full token. Copy it immediately and store it securely. If you lose it, you will need to revoke it and generate a new one.
  6. Store Securely: Store your PAT in a secure location, such as an environment variable, a secret management service, or a secure configuration file, avoiding hardcoding it directly into your application's source code.

It is crucial to manage these tokens carefully, as they provide direct access to your Typeform account's data and functionality. If a token is compromised, revoke it immediately from your Typeform account settings and generate a new one.

Authenticated request example

Once you have obtained your Personal Access Token, you can include it in the Authorization header of your HTTP requests to the Typeform API. The token should be prefixed with Bearer, followed by a space.

Here's an example using cURL to retrieve a list of forms from your Typeform account:

curl -X GET \
  'https://api.typeform.com/forms' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN'

In this example:

  • -X GET specifies the HTTP method.
  • 'https://api.typeform.com/forms' is the API endpoint to fetch forms.
  • -H 'Accept: application/json' indicates that the client expects a JSON response.
  • -H 'Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN' is the crucial authentication header. Replace YOUR_PERSONAL_ACCESS_TOKEN with the actual token you generated.

For JavaScript, using the fetch API, an authenticated request might look like this:

const accessToken = 'YOUR_PERSONAL_ACCESS_TOKEN';

fetch('https://api.typeform.com/forms', {
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'Authorization': `Bearer ${accessToken}`
  }
})
.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 fetching forms:', error);
});

Always ensure that your Personal Access Token is handled securely and is not exposed in client-side code or public repositories.

Security best practices

Securing your Typeform API integration is critical to protect your data and prevent unauthorized access. Adhering to these best practices will help maintain the integrity and confidentiality of your Typeform resources:

  1. Treat Personal Access Tokens (PATs) like passwords: Your PATs grant significant access to your Typeform account. Never hardcode them directly into your source code, commit them to version control systems (like Git), or expose them in client-side JavaScript. Instead, use environment variables, secret management services (e.g., AWS Secrets Manager, Google Cloud Secret Manager, Azure Key Vault), or secure configuration files.
  2. Use environment variables for tokens: For server-side applications, storing PATs as environment variables is a common and effective practice. This keeps them out of your codebase and allows for easy rotation without code changes.
  3. Implement the Principle of Least Privilege: When generating PATs, if Typeform provides options for scope or permission control, grant only the minimum necessary permissions for your application to function. For example, if your application only needs to read form responses, do not grant write or delete permissions. This minimizes the impact of a compromised token.
  4. Regularly rotate tokens: Periodically generate new PATs and revoke old ones. This practice reduces the window of opportunity for an attacker if a token is ever compromised without your knowledge. Establish a schedule for token rotation based on your organization's security policies.
  5. Monitor API usage: Keep an eye on your API usage patterns. Unusual spikes in activity or requests from unexpected IP addresses could indicate a compromised token or malicious activity.
  6. Secure your development environment: Ensure that your development machines and build pipelines are secure. Access to these environments could expose your API credentials.
  7. Validate and sanitize all input: If your application accepts user input that is then used in API requests (e.g., to filter or query data), always validate and sanitize this input to prevent injection attacks and other vulnerabilities.
  8. Use HTTPS exclusively: All communication with the Typeform API should occur over HTTPS to encrypt data in transit and prevent eavesdropping. Typeform API endpoints inherently enforce HTTPS, but always verify your application is not attempting insecure connections.
  9. Handle errors gracefully: Implement robust error handling in your application, especially for authentication failures. Avoid exposing sensitive information (like internal errors or stack traces) in error messages returned to clients.
  10. Review Typeform's security documentation: Regularly consult the official Typeform developer documentation for any updates to authentication methods or security recommendations.

By following these best practices, developers can significantly enhance the security posture of their Typeform API integrations, protecting both their data and their users' information.