Collecting Data from APIs
To test whether hot days really sell more cold coffee, Nisha needs daily temperatures for her city. She could copy them from a weather website by hand, one day at a time. Or the analyst can ask a weather service's API, and get a year of clean, structured data in one request.
The rule
An API is a menu for programs: send a request, get structured data back.
An API (application programming interface) is a doorway a service offers to other programs. Instead of a page designed for eyes, it returns data designed for code. Most web APIs follow the same shape:
- Endpoint: the address you call, such as
https://api.example-weather.com/v1/daily. - Parameters: what you are asking for, such as city and date range.
- Authentication: usually an API key, a secret string that identifies you. Keep it out of shared files.
- Response: a status code (200 means success, 401 means not authorised, 429 means too many requests) plus a body, usually JSON.
A request and part of its reply:
GET https://api.example-weather.com/v1/daily?city=Pune&start=2025-06-02&end=2025-06-08{
"city": "Pune",
"units": "celsius",
"days": [
{ "date": "2025-06-02", "max_temp": 31 },
{ "date": "2025-06-03", "max_temp": 29 }
]
}JSON is semi-structured: named fields, nested lists. To analyse it, you flatten it into a table with one row per day, then join it to sales on date.
Services protect themselves with rate limits (a maximum number of requests per minute or day) and pagination (long results split into pages you fetch one by one).