Authentication overview

Loops provides an email API designed for developers, facilitating both transactional and marketing email delivery. To ensure secure interactions with its services, Loops implements an API key-based authentication model. This approach requires that every request to the Loops API includes a valid, secret API key, which acts as a unique identifier and credential for your application or service. The use of API keys helps maintain the integrity and confidentiality of your email operations, preventing unauthorized access and ensuring that only designated systems can initiate email sends or manage audience data.

The API key system is a common method for authenticating programmatic access to web services, offering a balance between ease of implementation and security for many applications. When making a request to the Loops API, the API key is typically transmitted in a specific HTTP header, allowing the Loops servers to verify the sender's identity before processing the request. This mechanism is fundamental to protecting your account and ensuring that email campaigns and transactional messages are sent as intended.

Supported authentication methods

Loops primarily supports API key authentication for all interactions with its platform. This method is straightforward and widely adopted for server-to-server communication and applications where a consistent, programmatic identity is required. The API key serves as the sole credential needed for most API operations.

API Key Authentication

API keys are unique, secret tokens that you generate within your Loops account. These keys grant access to your Loops resources and API endpoints. When making an API call, the key must be included in the HTTP request headers. Loops uses these keys to identify and authorize your requests, linking them to your specific Loops account and its associated permissions. It is crucial to treat these keys as sensitive credentials, similar to passwords, due to the direct access they provide to your email sending capabilities and customer data.

The simplicity of API key authentication makes it suitable for a wide range of use cases, from backend services sending transactional emails (such as password resets or order confirmations) to automation scripts managing marketing campaigns. For developers using one of the Loops officially supported SDKs, the SDKs typically abstract away the direct management of adding the API key to request headers, simplifying the development process while maintaining secure communication.

Method When to Use Security Level
API Key Server-side applications, backend services, scripting, internal tools. Moderate (requires secure storage and transmission).

Getting your credentials

To begin using the Loops API, you first need to generate an API key from your Loops dashboard. This key will serve as your primary credential for all API interactions. Follow these steps to obtain your API key:

  1. Log in to your Loops account: Navigate to the Loops homepage and log in with your credentials.
  2. Access API Settings: Once logged in, locate the 'Settings' or 'API' section within your dashboard. The exact path might vary slightly, but it's typically found in the main navigation or under your profile settings. Refer to the Loops API documentation for the precise location.
  3. Generate New API Key: Within the API settings, you should find an option to generate a new API key. Loops allows you to create multiple API keys for different applications or environments (e.g., development, staging, production) to enhance security and organization.
  4. Copy Your API Key: After generating the key, it will be displayed on the screen. It is critical to copy this key immediately and store it securely, as it typically will not be shown again in its entirety for security reasons. If you lose an API key, you will need to revoke it and generate a new one.

Remember that each generated API key is unique to your account. You can also revoke existing API keys from this same section if they are compromised or no longer needed, which is an important security practice.

Authenticated request example

Once you have your Loops API key, you can use it to make authenticated requests to the API. The API key must be sent in the Authorization header of your HTTP requests, prefixed with Bearer. Below is an example of how to make an authenticated request using Node.js and the curl command-line tool.

Node.js Example

Using the Loops Node.js SDK, the API key is typically initialized when you create an instance of the Loops client. This abstracts the header management.

const LoopsClient = require('loops');

const loops = new LoopsClient({ apiKey: process.env.LOOPS_API_KEY });

async function sendTransactionalEmail() {
  try {
    const response = await loops.sendTransactional({ 
      to: '[email protected]',
      transactionalId: 'transactional_template_id',
      data: { name: 'John Doe' }
    });
    console.log('Email sent successfully:', response);
  } catch (error) {
    console.error('Error sending email:', error);
  }
}

sendTransactionalEmail();

cURL Example

For direct HTTP requests, you would include the Authorization header manually:

curl -X POST \ 
  https://app.loops.so/api/v1/transactional \ 
  -H 'Content-Type: application/json' \ 
  -H 'Authorization: Bearer YOUR_LOOPS_API_KEY' \ 
  -d '{ 
    "email": "[email protected]", 
    "transactionalId": "your_transactional_id", 
    "data": { "name": "Jane Doe" } 
  }'

Replace YOUR_LOOPS_API_KEY with your actual API key and adjust the email, transactionalId, and data fields as necessary for your specific use case. The Loops API reference documentation provides further details on available endpoints and request bodies.

Security best practices

Protecting your Loops API keys is paramount to maintaining the security of your email communications and customer data. Adhering to robust security practices can mitigate risks such as unauthorized access, data breaches, and service abuse.

  • Store API Keys Securely: Never hardcode API keys directly into your application's source code. Instead, use environment variables, secret management services (e.g., AWS Secrets Manager, Google Secret Manager, Azure Key Vault), or secure configuration files that are not committed to version control. This prevents accidental exposure in public repositories. For guidance on secure storage, consider reviewing Google Cloud's best practices for managing secrets.
  • Rotate API Keys Regularly: Periodically rotate your API keys (e.g., every 90 days). This practice limits the window of exposure if a key is compromised. Loops allows you to generate new keys and revoke old ones without service interruption if done carefully.
  • Principle of Least Privilege: If Loops introduces more granular permissions for API keys in the future, always assign the minimum necessary permissions to each key. For now, treat all API keys as having full access to your Loops account's API capabilities.
  • Monitor API Key Usage: Regularly check your Loops dashboard or logs for unusual API activity. Spikes in requests, requests from unexpected geographical locations, or failed authentication attempts could indicate a compromised key.
  • Secure Development Environment: Ensure that your development and testing environments are secure. Avoid using production API keys in non-production environments. Use separate, restricted keys for development and staging.
  • HTTPS Everywhere: Always use HTTPS for all API communications. Loops API endpoints are served over HTTPS, which encrypts data in transit and protects your API key from interception during transmission. This is a fundamental web security practice, detailed in resources like MDN Web Docs on HTTPS.
  • Revoke Compromised Keys Immediately: If you suspect an API key has been compromised, revoke it immediately from your Loops dashboard and replace it with a newly generated key.
  • Client-Side vs. Server-Side: Loops API keys are inherently secret and should only be used in server-side applications where they cannot be exposed to end-users. Never embed your Loops API key directly in client-side code (e.g., JavaScript in a web browser or mobile app).