Getting started overview
Integrating with Tomorrow's API involves a sequence of steps to ensure proper authentication and data retrieval. This guide covers account creation, API key acquisition, and executing an initial API call. The general workflow is:
- Sign Up: Create an account on the Tomorrow platform.
- API Key Retrieval: Locate and copy your unique API key from the developer dashboard.
- Construct Request: Formulate an API request, including your API key for authentication.
- Execute Request: Send the request to a Tomorrow API endpoint.
- Process Response: Parse the JSON response to extract the desired weather data.
Tomorrow provides a Developer Plan that offers 500 API calls per day, suitable for initial development and testing before committing to a paid tier. The API uses a RESTful design, preferring JSON for both requests and responses, a common practice for web APIs as outlined by the W3C's architectural principles for REST.
Create an account and get keys
Before making any API calls, an account is required to generate an API key. This key authenticates your requests and tracks your API usage against your plan limits.
Account Creation Process
- Navigate to Tomorrow's website: Go to the official Tomorrow homepage.
- Sign Up: Look for a 'Sign Up' or 'Get Started' button, usually located in the top navigation or prominent on the landing page.
- Choose a Plan: Select the Developer Plan to start with the free tier. This plan provides 500 API calls per day, which is sufficient for initial exploration and development.
- Provide Details: Complete the registration form with your email, password, and any other required information.
- Verify Email: Check your inbox for a verification email and follow the instructions to activate your account.
Retrieving Your API Key
Once your account is active, your API key will be available in your developer dashboard:
- Log In: Access your Tomorrow account dashboard using your newly created credentials.
- Locate API Keys Section: Navigate to the section labeled 'API Keys' or 'Developer Settings'. The exact label may vary but is typically intuitive.
- Copy Key: Your unique API key will be displayed. Copy this key. It is a long alphanumeric string that you will include in all your API requests to authenticate them. Treat your API key like a password; do not expose it in client-side code or public repositories.
Your first request
With an API key in hand, you can now construct and execute your first API call. This example demonstrates fetching a current weather forecast.
API Endpoint Structure
Tomorrow's API endpoints generally follow a structure that includes the base URL, the API version, the specific data layer (e.g., weather, airQuality), the endpoint (e.g., forecast, realtime), and query parameters for location, units, and your API key.
For a real-time weather forecast, a common endpoint is /v4/weather/realtime. The Tomorrow API reference documentation provides comprehensive details on available endpoints and their parameters.
Example: Real-time Weather Forecast (cURL)
The following cURL command retrieves real-time weather data for a specified location (e.g., Central Park, New York) using your API key. Replace YOUR_API_KEY with the key you obtained from your dashboard.
curl "https://api.tomorrow.io/v4/weather/realtime?location=40.7831,-73.9712&units=imperial&apikey=YOUR_API_KEY"
Parameters Explained:
location: Required. The geographical coordinates (latitude, longitude) of the desired location. Example:40.7831,-73.9712for Central Park, New York.units: Optional. Specifies the unit system for the response. Options includeimperial(Fahrenheit, miles per hour) ormetric(Celsius, meters per second).apikey: Required. Your unique API key for authentication.
Example: Real-time Weather Forecast (Python)
This Python example uses the requests library to achieve the same result:
import requests
API_KEY = "YOUR_API_KEY" # Replace with your actual API key
LOCATION = "40.7831,-73.9712"
UNITS = "imperial"
url = f"https://api.tomorrow.io/v4/weather/realtime?location={LOCATION}&units={UNITS}&apikey={API_KEY}"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print("Current Temperature:", data['data']['values']['temperature'], f"°{ 'F' if UNITS == 'imperial' else 'C' }")
print("Weather Condition:", data['data']['values']['weatherCode'])
else:
print(f"Error: {response.status_code} - {response.text}")
Example: Real-time Weather Forecast (Node.js)
A Node.js implementation using node-fetch (install with npm install node-fetch):
const fetch = require('node-fetch');
const API_KEY = "YOUR_API_KEY"; // Replace with your actual API key
const LOCATION = "40.7831,-73.9712";
const UNITS = "imperial";
const url = `https://api.tomorrow.io/v4/weather/realtime?location=${LOCATION}&units=${UNITS}&apikey=${API_KEY}`;
async function getRealtimeWeather() {
try {
const response = await fetch(url);
const data = await response.json();
if (response.ok) {
console.log("Current Temperature:", data.data.values.temperature, `°${ UNITS === 'imperial' ? 'F' : 'C' }`);
console.log("Weather Condition:", data.data.values.weatherCode);
} else {
console.error(`Error: ${response.status} - ${JSON.stringify(data)}`);
}
} catch (error) {
console.error("Fetch error:", error);
}
}
getRealtimeWeather();
Interpreting the Response
A successful response will return a JSON object containing current weather data. The structure typically includes a data object, which in turn contains a values object with various weather parameters like temperature, humidity, windSpeed, and weatherCode. The Tomorrow data layers overview details the available fields.
Common next steps
After successfully making your first request, consider these common next steps to further integrate Tomorrow's API into your application:
- Explore Other Endpoints: Investigate endpoints for historical data, daily forecasts, air quality, or pollen data to meet specific application requirements.
- Error Handling: Implement robust error handling in your code to manage API limits, invalid requests, and other potential issues. The Tomorrow error codes documentation provides a list of common error responses and their meanings.
- Location Search: Integrate a method for resolving location names into coordinates, such as using a geocoding API like Google Maps Geocoding. Tomorrow's API directly accepts latitude/longitude.
- API Usage Monitoring: Regularly check your dashboard to monitor API call usage and ensure you remain within your plan limits.
- Upgrade Plan: If your application requires more than 500 daily API calls or access to advanced features, consider upgrading to a paid plan.
Troubleshooting the first call
Encountering issues with your initial API call is common. Here's a table of common problems and their solutions:
| Problem | Likely Cause | Solution |
|---|---|---|
401 Unauthorized |
Invalid or missing API key. | Double-check your API key for typos. Ensure it's correctly included as the apikey query parameter. Confirm your account is active. |
400 Bad Request |
Missing or malformed required parameters (e.g., location). Incorrect URL syntax. |
Verify all required parameters are present and correctly formatted. Consult the API reference documentation for endpoint-specific requirements. |
429 Too Many Requests |
Exceeded your API call limit (500 calls/day on Developer Plan). | Wait for the daily limit to reset (UTC midnight) or consider upgrading your Tomorrow plan. Implement rate limiting in your application. |
500 Internal Server Error |
An issue on Tomorrow's server side. | This is rare. Wait a few minutes and retry the request. If the problem persists, check the Tomorrow status page (if available) or contact their support. |
| No data returned or unexpected value in response. | Incorrect location, units, or fields parameters. |
Carefully review the parameters in your request against the Tomorrow API documentation. Ensure coordinates are correct and within supported ranges. |
For more detailed troubleshooting, refer to the Tomorrow API error codes documentation.