Authentication overview
Postali secures access to its Geocoding, Reverse Geocoding, Address Validation, and Timezone APIs primarily through API key authentication. This approach enables client applications to prove their identity when making requests, ensuring that usage is tracked and unauthorized access is prevented. The API key serves as the credential for identifying the requesting application or user within the Postali ecosystem.
When an API key is used for authentication, it is typically included as a query parameter in the API request URL or, in some cases, as a header. Postali's documentation specifies the use of a query parameter for key transmission. All communication with the Postali API must occur over HTTPS to protect the API key and other sensitive data during transit, mitigating risks such as man-in-the-middle attacks. This standard practice aligns with recommendations for securing web APIs more broadly, as outlined by organizations like the World Wide Web Consortium on web security.
Postali offers a JSON-based RESTful API with extensive documentation and SDKs in multiple programming languages, including JavaScript, Python, PHP, Ruby, Go, Java, and C#. These SDKs often abstract the authentication process, allowing developers to configure the API key once and have it automatically included in subsequent requests.
Supported authentication methods
Postali primarily supports API key authentication for accessing its services. This method involves generating a unique key from the Postali developer dashboard and including it with each API request. The API key identifies the client and is used for rate limiting, billing, and access control.
API Key Authentication
API key authentication is a straightforward method where a unique, secret string is provided with each request. For Postali, this key grants access to the associated account's usage quotas and enabled API features. It is crucial to manage API keys securely to prevent unauthorized use.
When to use API Key authentication:
- Server-side applications where the API key can be stored securely and not exposed to client-side code.
- Applications with moderate security requirements where the API key is transmitted over HTTPS.
- Rapid prototyping and development due to its simplicity.
While API key authentication is effective for many use cases, it is generally less secure than token-based authentication methods like OAuth 2.0 when dealing with user-specific data or third-party integrations, as noted in various developer guides for authentication. However, for Postali's core services, which primarily involve location data lookups for a single application, API keys are a suitable and common choice.
Authentication Methods Overview
| Method | When to Use | Security Level |
|---|---|---|
| API Key (Query Parameter) | Server-side applications, direct access to Postali services, usage tracking. | Medium (requires secure storage and HTTPS transmission) |
Getting your credentials
To use Postali's APIs, you need to obtain an API key. This key is provisioned through the Postali developer portal after account registration. The process typically involves:
- Sign up or Log in: Navigate to the Postali homepage and create a new account or log in to an existing one.
- Access Developer Dashboard: Once logged in, locate the developer dashboard or API settings section. This is usually accessible via a menu item like 'API Keys', 'Settings', or 'Developer'.
- Generate API Key: Within the API settings, there will be an option to generate a new API key. Some platforms allow you to create multiple keys for different projects or environments (e.g., development, staging, production) to enhance security and key management.
- Copy Your Key: After generation, your unique API key will be displayed. It is crucial to copy this key immediately and store it securely, as it may not be displayed again for security reasons. If lost, you might need to generate a new one, invalidating the previous key.
- Configure Environment: Store the API key in a secure environment variable or configuration file within your application, rather than hardcoding it directly into your source code.
Postali provides a free tier that allows up to 2,500 requests per day, making it possible to obtain and test API keys without immediate billing. Paid plans start at $10/month for 50,000 requests/day, as detailed on the Postali pricing page.
Authenticated request example
This example demonstrates how to make an authenticated request to the Postali Geocoding API using a placeholder API key. The API key is passed as a query parameter named apiKey.
HTTP Request
GET https://api.postali.co/v1/geocode?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&apiKey=YOUR_POSTALI_API_KEY HTTP/1.1
Host: api.postali.co
JavaScript (using Fetch API)
const POSTALI_API_KEY = 'YOUR_POSTALI_API_KEY';
const address = '1600 Amphitheatre Parkway, Mountain View, CA';
const encodedAddress = encodeURIComponent(address);
fetch(`https://api.postali.co/v1/geocode?address=${encodedAddress}&apiKey=${POSTALI_API_KEY}`)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Geocoding Result:', data);
})
.catch(error => {
console.error('Error fetching geocoding data:', error);
});
Python (using requests library)
import requests
POSTALI_API_KEY = 'YOUR_POSTALI_API_KEY'
address = '1600 Amphitheatre Parkway, Mountain View, CA'
params = {
'address': address,
'apiKey': POSTALI_API_KEY
}
response = requests.get('https://api.postali.co/v1/geocode', params=params)
if response.status_code == 200:
data = response.json()
print('Geocoding Result:', data)
else:
print(f'Error fetching geocoding data: {response.status_code} - {response.text}')
In all examples, replace YOUR_POSTALI_API_KEY with the actual API key obtained from your Postali account. For production environments, sensitive information like API keys should be loaded from environment variables or a secure configuration system, not hardcoded.
Security best practices
Properly securing your API keys is critical to prevent unauthorized access to your Postali account and services. Adhering to these best practices can significantly reduce security risks:
- Keep API Keys Confidential: Treat your API keys like passwords. Never hardcode them directly into client-side code (e.g., JavaScript in a web page or mobile app) where they can be easily extracted by end-users. Instead, store them in secure server-side environments or use environment variables.
- Use HTTPS for All Requests: Always ensure that all communication with the Postali API uses HTTPS. This encrypts the data in transit, protecting your API key and other sensitive data from interception. Postali's API reference implicitly requires HTTPS for its endpoints, as do most modern APIs, to establish a secure connection, as described in the IETF's HTTP/1.1 Message Syntax and Routing specification.
- Restrict API Key Privileges: While Postali's API keys typically grant access to all services on your account, if there were options for granular permissions, you would configure keys with the minimum necessary permissions required for the specific application.
- Rotate API Keys Regularly: Periodically generate new API keys and revoke old ones. This practice limits the window of opportunity for a compromised key to be exploited. A common rotation schedule might be every 90 days or annually, depending on your organization's security policies.
- Monitor API Key Usage: Regularly review your Postali API usage logs for any unusual activity. Spikes in requests or requests from unexpected geographical locations could indicate a compromised key.
- Implement Rate Limiting and Quotas: While Postali enforces its own rate limits, ensure your application also implements client-side rate limiting to prevent accidental or malicious overuse of your API key, which could lead to unexpected charges or service disruptions.
- Avoid Exposure in Version Control: Never commit API keys or configuration files containing them directly into public or private version control systems like Git. Use
.gitignorefiles to exclude such files. - Use Environment Variables: For server-side applications, store API keys as environment variables. This prevents them from being exposed in your codebase and allows for easy configuration changes across different deployment environments.
By implementing these security measures, developers can maintain the integrity and confidentiality of their Postali API keys, safeguarding their applications and data.