Authentication overview

Battuta provides geospatial services through its Geocoding, Reverse Geocoding, and IP Geolocation APIs. To access these services, client applications must authenticate their requests. Authentication verifies the identity of the client making the request, ensuring that only authorized users consume API resources and that usage can be tracked against specific accounts. For Battuta, this process is streamlined using a single, unique API key associated with your account.

The API key serves as both an identifier and a secret token. When a request is made to any Battuta endpoint, the API key must be included in the request URL. The Battuta API then validates this key against its records. If the key is valid and active, the request is processed; otherwise, the API returns an authentication error, preventing unauthorized access and resource consumption. This method is common for web services that prioritize ease of integration for developers while maintaining a necessary level of security for resource management and billing.

Developers should refer to the Battuta API documentation for specific endpoint details and example requests once they have obtained their API key.

Supported authentication methods

Battuta currently supports API Key authentication as its primary method for securing API access. This method involves passing a unique, secret string (the API key) with each request to identify and authenticate the calling application or user.

Method When to Use Security Level
API Key (URL Parameter) For direct client-side or server-side API calls where simplicity and ease of integration are priorities. Suitable for most Battuta use cases. Moderate. Requires careful handling to prevent exposure, as the key is visible in the URL.

While API keys offer simplicity, it is crucial to understand their security implications. Unlike more complex methods like OAuth 2.0, which involves token exchange and refresh mechanisms, API keys are static credentials. This means that if an API key is compromised, it can be used indefinitely until it is revoked or regenerated. Therefore, proper storage and transmission practices are essential to mitigate risks.

Getting your credentials

To begin using the Battuta API, you first need to obtain an API key. This key is provisioned through your Battuta account. Follow these steps to generate and retrieve your API key:

  1. Create a Battuta Account: If you do not already have an account, navigate to the Battuta homepage and sign up. Account creation typically involves providing an email address and setting a password.
  2. Log In: Once your account is created and verified, log in to your Battuta dashboard.
  3. Navigate to API Key Section: Within your dashboard, look for a section labeled something similar to "API Keys," "Developers," or "Settings." The exact navigation may vary, but it will be clearly identifiable.
  4. Generate New Key: If you don't have an existing key, or if you need a new one for a different application, there will typically be an option to "Generate New Key" or "Create API Key."
  5. Copy Your API Key: Once generated, your unique API key will be displayed. Copy this key immediately and store it securely. Battuta typically only displays the full key once upon generation for security reasons.
  6. Review Usage Limits: Familiarize yourself with the Battuta pricing and usage limits, including the free tier of 2,500 requests per month, to understand how your API key usage will be tracked.

Your API key is a unique identifier for your account and should be treated as a sensitive credential. Avoid hardcoding it directly into client-side code that is exposed to end-users, or committing it to public version control systems.

Authenticated request example

Once you have your API key, you can use it to make authenticated requests to Battuta's API endpoints. The API key is typically passed as a query parameter named key in the request URL. Here's an example using cURL for a geocoding request:

curl "https://battuta.io/api/geocode/v1/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY"

In this example:

  • https://battuta.io/api/geocode/v1/json is the base URL for the Geocoding API endpoint.
  • address=1600+Amphitheatre+Parkway,+Mountain+View,+CA is the address parameter for which you want to retrieve geocoding information.
  • key=YOUR_API_KEY is where you replace YOUR_API_KEY with the actual API key you obtained from your Battuta dashboard.

For JavaScript applications, particularly those running server-side or in environments where the key can be secured, an example might look like this:

const API_KEY = process.env.BATTUTA_API_KEY; // Stored securely
const address = "Eiffel Tower, Paris";

fetch(`https://battuta.io/api/geocode/v1/json?address=${encodeURIComponent(address)}&key=${API_KEY}`)
  .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 geocoding data:", error);
  });

This JavaScript example demonstrates fetching data using the Fetch API, emphasizing the use of an environment variable for the API key, which is a recommended security practice. Battuta also provides SDKs and examples in other primary languages like Python and PHP within its documentation.

Security best practices

Securing your Battuta API key is essential to prevent unauthorized access to your account and API usage. Adhering to these best practices can help protect your credentials:

  1. Do Not Expose API Keys in Client-Side Code: Never embed your Battuta API key directly into public client-side code (e.g., JavaScript in a web browser). If your application needs to make direct API calls from the client, consider using a proxy server to append the API key securely on the server-side, or implement rate limiting and domain restrictions if Battuta supports them (check Battuta's security documentation for specific features).
  2. Use Environment Variables or Secret Management Services: For server-side applications, store your API key in environment variables (e.g., BATTUTA_API_KEY) rather than hardcoding it into your source code. For more complex deployments, consider using dedicated secret management services like AWS Secrets Manager or Google Secret Manager to securely store and retrieve credentials. This prevents the key from being exposed if your codebase is compromised or publicly shared.
  3. Restrict API Key Usage: If Battuta offers features to restrict API keys by IP address or HTTP referrer, utilize them. This adds an extra layer of security, ensuring that even if your key is compromised, it can only be used from authorized locations or domains. Always consult the Battuta API reference for available security features.
  4. Regularly Rotate API Keys: Periodically generate new API keys and revoke old ones. This practice minimizes the window of opportunity for a compromised key to be exploited. A common rotation schedule might be every 90 days, or immediately if a potential compromise is suspected.
  5. Monitor API Usage: Regularly check your Battuta account dashboard for unusual API usage patterns. Spikes in requests or usage from unexpected regions could indicate a compromised key.
  6. Implement Least Privilege: If Battuta introduces different types of API keys with varying permissions in the future, always use the key with the minimum necessary privileges for a given task. This limits the damage a compromised key can inflict.
  7. Secure Your Development Environment: Ensure that your local development environment and CI/CD pipelines are secure. Avoid storing API keys in plain text files or insecure configuration files.
  8. Understand Transport Layer Security (TLS): All communication with Battuta APIs should occur over HTTPS. This encrypts the data in transit, including your API key, protecting it from eavesdropping. Modern API clients and libraries typically enforce HTTPS by default, but it's important to verify. The IETF's TLS 1.3 specification provides comprehensive details on secure communication protocols.