Learn how to authenticate with ObservEarth's APIs and manage your API keys securely.
X-API-Key
header.
To use ObservEarth's APIs, you need an API key. Here's how to get one:
To authenticate your API requests, include your API key in the X-API-Key
header of each request.
import requests
api_key = "your_api_key_here"
url = "https://observearth.com/api/geometry/"
headers = {
"X-API-Key": api_key,
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
data = response.json()
print(data)
const apiKey = "your_api_key_here";
const url = "https://observearth.com/api/geometry/";
fetch(url, {
method: "GET",
headers: {
"X-API-Key": apiKey,
"Content-Type": "application/json"
}
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
curl -X GET "https://observearth.com/api/geometry/" \
-H "X-API-Key: your_api_key_here" \
-H "Content-Type: application/json"
Protecting your API key is crucial. Here are some best practices:
# Python example using environment variables
import os
import requests
api_key = os.environ.get("OBSERVEARTH_API_KEY")
url = "https://observearth.com/api/geometry/"
headers = {
"X-API-Key": api_key,
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
When authentication fails, you'll receive one of these HTTP status codes:
Status Code | Description | Solution |
---|---|---|
401 Unauthorized | Missing API key | Include the X-API-Key header in your request |
403 Forbidden | Invalid API key | Check that your API key is correct |
429 Too Many Requests | Rate limit exceeded | Implement backoff strategy or upgrade your plan |
import requests
api_key = "your_api_key_here"
url = "https://observearth.com/api/geometry/"
headers = {
"X-API-Key": api_key,
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
if response.status_code == 401:
print("Error: Missing API key")
elif response.status_code == 403:
print("Error: Invalid API key")
elif response.status_code == 429:
retry_after = response.headers.get("Retry-After", "60")
print(f"Rate limit exceeded. Try again in {retry_after} seconds")
elif response.status_code == 200:
data = response.json()
print(data)
else:
print(f"Error: {response.status_code}")
print(response.text)
Now that you understand authentication, you can: