# Recipe: Current Conditions

import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "zudoku/ui/Accordion";

export const StepHeader = ({ n, children }) => (
  <span style={{ display: "inline-flex", alignItems: "center", gap: "0.75rem" }}>
    <span style={{
      display: "inline-flex",
      alignItems: "center",
      justifyContent: "center",
      width: "1.75rem",
      height: "1.75rem",
      minWidth: "1.75rem",
      borderRadius: "9999px",
      backgroundColor: "#F05514",
      color: "#FFFFFF",
      fontSize: "0.875rem",
      fontWeight: 600,
      flexShrink: 0,
      lineHeight: 1,
    }}>
      {n}
    </span>
    <span>{children}</span>
  </span>
);

This recipe shows how to retrieve live weather data — temperature, weather phrase, precipitation status, and more — for a specific location.

:::note
**These recipes are teaching examples — not production code.**

- **Host:** examples use the development host **apidev.accuweather.com**. Switch to **api.accuweather.com** for production.
- **Production hardening:** GZIP compression, caching, retries with exponential backoff, and error handling are not included. See the [Best Practices](/developers/best-practices) guide.
:::

## Scenario

> "I want to show users the current temperature and weather description for their city right now."

:::note

You'll need a **LocationKey** before starting. If you don't have one, follow the [Location Search recipe](/recipes/location-search) first.
For this example we use LocationKey `349727` (New York City).

:::

---

<Accordion type="multiple" defaultValue={["step-1"]} className="my-6">

<AccordionItem value="step-1">
  <AccordionTrigger><StepHeader n={1}>Make the request</StepHeader></AccordionTrigger>
  <AccordionContent>

Call the Current Conditions endpoint with your LocationKey.

**Endpoint:**
```
GET https://apidev.accuweather.com/currentconditions/v1/{locationKey}.json?apikey={YOUR_API_KEY}
```

<CodeTabs syncKey="language">

```ts title="TypeScript"
const apiKey = "{YOUR_API_KEY}";
const locationKey = "349727";

const response = await fetch(
  `https://apidev.accuweather.com/currentconditions/v1/${locationKey}.json?apikey=${apiKey}`
);
const data: Record<string, any>[] = await response.json();
const conditions = data[0]; // API returns an array; take the first element
```

```python title="Python"
import requests

api_key = "{YOUR_API_KEY}"
location_key = "349727"

response = requests.get(
    f"https://apidev.accuweather.com/currentconditions/v1/{location_key}.json",
    params={"apikey": api_key},
)
conditions = response.json()[0]  # API returns an array; take the first element
```

```csharp title="C#"
using var client = new HttpClient();

var apiKey = "{YOUR_API_KEY}";
var locationKey = "349727";
var url = $"https://apidev.accuweather.com/currentconditions/v1/{locationKey}.json?apikey={apiKey}";
var response = await client.GetAsync(url);
var data = await response.Content.ReadAsStringAsync();
```

```java title="Java"
HttpClient client = HttpClient.newHttpClient();
String apiKey = "{YOUR_API_KEY}";
String locationKey = "349727";
HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://apidev.accuweather.com/currentconditions/v1/"
        + locationKey + ".json?apikey=" + apiKey))
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
String data = response.body();
```

```bash title="bash"
curl "https://apidev.accuweather.com/currentconditions/v1/349727.json?apikey={YOUR_API_KEY}"
```

</CodeTabs>

  </AccordionContent>
</AccordionItem>

<AccordionItem value="step-2">
  <AccordionTrigger><StepHeader n={2}>Inspect the response</StepHeader></AccordionTrigger>
  <AccordionContent>

```json
[
  {
    "LocalObservationDateTime": "2024-06-15T14:35:00-04:00",
    "EpochTime": 1718476500,
    "WeatherText": "Partly cloudy",
    "WeatherIcon": 3,
    "HasPrecipitation": false,
    "PrecipitationType": null,
    "IsDayTime": true,
    "Temperature": {
      "Metric": {
        "Value": 24.4,
        "Unit": "C",
        "UnitType": 17
      },
      "Imperial": {
        "Value": 76,
        "Unit": "F",
        "UnitType": 18
      }
    },
    "MobileLink": "https://m.accuweather.com/...",
    "Link": "https://www.accuweather.com/..."
  }
]
```

:::tip

The response is always an **array** even though it contains only one object. Remember to index into `[0]` (or destructure) before accessing fields.

:::

  </AccordionContent>
</AccordionItem>

<AccordionItem value="step-3">
  <AccordionTrigger><StepHeader n={3}>Display the data</StepHeader></AccordionTrigger>
  <AccordionContent>

<CodeTabs syncKey="language">

```ts title="TypeScript"
const { WeatherText, Temperature, HasPrecipitation, IsDayTime } = conditions;

console.log(`Conditions: ${WeatherText}`);
console.log(`Temperature: ${Temperature.Imperial.Value}°F / ${Temperature.Metric.Value}°C`);
console.log(`Precipitation: ${HasPrecipitation ? "Yes" : "None"}`);
console.log(`Daytime: ${IsDayTime}`);
```

```python title="Python"
print(f"Conditions: {conditions['WeatherText']}")
print(f"Temperature: {conditions['Temperature']['Imperial']['Value']}°F / "
      f"{conditions['Temperature']['Metric']['Value']}°C")
print(f"Precipitation: {'Yes' if conditions['HasPrecipitation'] else 'None'}")
print(f"Daytime: {conditions['IsDayTime']}")
```

```csharp title="C#"
using System.Text.Json;

var doc = JsonDocument.Parse(data);
var conditions = doc.RootElement[0];

var weatherText = conditions.GetProperty("WeatherText").GetString();
var tempF = conditions.GetProperty("Temperature").GetProperty("Imperial").GetProperty("Value").GetDouble();
var tempC = conditions.GetProperty("Temperature").GetProperty("Metric").GetProperty("Value").GetDouble();
var hasPrecip = conditions.GetProperty("HasPrecipitation").GetBoolean();
var isDayTime = conditions.GetProperty("IsDayTime").GetBoolean();

Console.WriteLine($"Conditions: {weatherText}");
Console.WriteLine($"Temperature: {tempF}°F / {tempC}°C");
Console.WriteLine($"Precipitation: {(hasPrecip ? "Yes" : "None")}");
Console.WriteLine($"Daytime: {isDayTime}");
```

```java title="Java"
import org.json.JSONArray;

var conditions = new JSONArray(data).getJSONObject(0);

var weatherText = conditions.getString("WeatherText");
var tempF = conditions.getJSONObject("Temperature").getJSONObject("Imperial").getDouble("Value");
var tempC = conditions.getJSONObject("Temperature").getJSONObject("Metric").getDouble("Value");
var hasPrecip = conditions.getBoolean("HasPrecipitation");
var isDayTime = conditions.getBoolean("IsDayTime");

System.out.println("Conditions: " + weatherText);
System.out.println("Temperature: " + tempF + "°F / " + tempC + "°C");
System.out.println("Precipitation: " + (hasPrecip ? "Yes" : "None"));
System.out.println("Daytime: " + isDayTime);
```

```bash title="bash"
echo "$DATA" | jq -r '.[0] |
  "Conditions: \(.WeatherText)\n" +
  "Temperature: \(.Temperature.Imperial.Value)°F / \(.Temperature.Metric.Value)°C\n" +
  "Precipitation: \(if .HasPrecipitation then "Yes" else "None" end)\n" +
  "Daytime: \(.IsDayTime)"'
```

</CodeTabs>

  </AccordionContent>
</AccordionItem>

</Accordion>

---

## Extended details

Add `details=true` to receive an expanded set of fields including humidity, wind, UV index, ceiling, and more.

<CodeTabs syncKey="language">

```ts title="TypeScript"
const detailsResponse = await fetch(
  `https://apidev.accuweather.com/currentconditions/v1/${locationKey}.json?apikey=${apiKey}&details=true`
);
const detailedData: Record<string, any>[] = await detailsResponse.json();
```

```python title="Python"
details_response = requests.get(
    f"https://apidev.accuweather.com/currentconditions/v1/{location_key}.json",
    params={"apikey": api_key, "details": "true"},
)
detailed_data = details_response.json()
```

```csharp title="C#"
var detailsUrl = $"https://apidev.accuweather.com/currentconditions/v1/{locationKey}.json?apikey={apiKey}&details=true";
var detailsResponse = await client.GetAsync(detailsUrl);
var detailedData = await detailsResponse.Content.ReadAsStringAsync();
```

```java title="Java"
HttpRequest detailsRequest = HttpRequest.newBuilder()
    .uri(URI.create("https://apidev.accuweather.com/currentconditions/v1/"
        + locationKey + ".json?apikey=" + apiKey + "&details=true"))
    .build();

HttpResponse<String> detailsResponse = client.send(detailsRequest, HttpResponse.BodyHandlers.ofString());
String detailedData = detailsResponse.body();
```

```bash title="bash"
curl "https://apidev.accuweather.com/currentconditions/v1/349727.json?apikey={YOUR_API_KEY}&details=true"
```

</CodeTabs>

Additional fields returned with `details=true`:

```json
{
  "RelativeHumidity": 55,
  "DewPoint": {
    "Metric": { "Value": 14.4, "Unit": "C", "UnitType": 17 },
    "Imperial": { "Value": 58, "Unit": "F", "UnitType": 18 }
  },
  "Wind": {
    "Direction": { "Degrees": 200, "Localized": "SSW", "English": "SSW" },
    "Speed": {
      "Metric": { "Value": 14.5, "Unit": "km/h", "UnitType": 7 },
      "Imperial": { "Value": 9, "Unit": "mi/h", "UnitType": 9 }
    }
  },
  "UVIndex": 5,
  "UVIndexText": "Moderate",
  "Visibility": {
    "Metric": { "Value": 16.1, "Unit": "km", "UnitType": 6 },
    "Imperial": { "Value": 10, "Unit": "mi", "UnitType": 2 }
  },
  "Pressure": {
    "Metric": { "Value": 1013.7, "Unit": "mb", "UnitType": 14 },
    "Imperial": { "Value": 29.93, "Unit": "inHg", "UnitType": 12 }
  },
  "CloudCover": 40,
  "ApparentTemperature": {
    "Metric": { "Value": 23.9, "Unit": "C", "UnitType": 17 },
    "Imperial": { "Value": 75, "Unit": "F", "UnitType": 18 }
  }
}
```

---

## Key response fields

| Field | Type | Description |
|-------|------|-------------|
| `WeatherText` | String | Plain-language current conditions (e.g., "Partly cloudy") |
| `WeatherIcon` | Integer | Icon code (1–44); maps to AccuWeather icon set |
| `HasPrecipitation` | Boolean | Whether precipitation is currently falling |
| `PrecipitationType` | String \| null | `"Rain"`, `"Snow"`, `"Ice"`, `"Mixed"`, or `null` |
| `IsDayTime` | Boolean | Whether it is currently daytime at the location |
| `Temperature.Metric.Value` | Number | Current temperature in Celsius |
| `Temperature.Imperial.Value` | Number | Current temperature in Fahrenheit |
| `LocalObservationDateTime` | String | ISO 8601 timestamp of the observation |
| `EpochTime` | Integer | Unix epoch timestamp of the observation |

---

## Get historical current conditions

The API also supports the **past 6 hours** and **past 24 hours** of observations:

```bash
# Past 6 hours
curl "https://apidev.accuweather.com/currentconditions/v1/349727/historical.json?apikey={YOUR_API_KEY}"

# Past 24 hours
curl "https://apidev.accuweather.com/currentconditions/v1/349727/historical/24.json?apikey={YOUR_API_KEY}"
```

Each returns an array of up to 6 (or 24) observation snapshots in reverse chronological order.

---

## Complete code sample

Copy a full, runnable example that fetches current conditions and prints a summary.

<CodeTabs syncKey="language">

```ts title="TypeScript"
const API_KEY = "{YOUR_API_KEY}";
const locationKey = "349727";

// Step 1: Fetch current conditions
const res = await fetch(
  `https://apidev.accuweather.com/currentconditions/v1/${locationKey}.json?apikey=${API_KEY}`
);
const data: Record<string, any>[] = await res.json();

// Step 2: Parse the first item from the array
const conditions = data[0];

// Step 3: Display a formatted summary
console.log("\nCurrent Conditions");
console.log("━".repeat(42));
console.log(`Conditions:    ${conditions.WeatherText}`);
console.log(`Temperature:   ${conditions.Temperature.Imperial.Value}°F / ${conditions.Temperature.Metric.Value}°C`);
console.log(`Precipitation: ${conditions.HasPrecipitation ? "Yes" : "None"}`);
console.log(`Daytime:       ${conditions.IsDayTime}`);
```

```python title="Python"
import requests

API_KEY = "{YOUR_API_KEY}"
location_key = "349727"

# Step 1: Fetch current conditions
resp = requests.get(
    f"https://apidev.accuweather.com/currentconditions/v1/{location_key}.json",
    params={"apikey": API_KEY},
)

# Step 2: Parse the first item from the array
conditions = resp.json()[0]

# Step 3: Display a formatted summary
print("\nCurrent Conditions")
print("━" * 42)
print(f"Conditions:    {conditions['WeatherText']}")
print(f"Temperature:   {conditions['Temperature']['Imperial']['Value']}°F / "
      f"{conditions['Temperature']['Metric']['Value']}°C")
print(f"Precipitation: {'Yes' if conditions['HasPrecipitation'] else 'None'}")
print(f"Daytime:       {conditions['IsDayTime']}")
```

```csharp title="C#"
using System.Text.Json;

var apiKey = "{YOUR_API_KEY}";
var locationKey = "349727";

// Step 1: Fetch current conditions
using var client = new HttpClient();
var response = await client.GetStringAsync(
    $"https://apidev.accuweather.com/currentconditions/v1/{locationKey}.json?apikey={apiKey}");

// Step 2: Parse the first item from the array
using var doc = JsonDocument.Parse(response);
var conditions = doc.RootElement[0];

var weatherText = conditions.GetProperty("WeatherText").GetString();
var tempF = conditions.GetProperty("Temperature").GetProperty("Imperial").GetProperty("Value").GetDouble();
var tempC = conditions.GetProperty("Temperature").GetProperty("Metric").GetProperty("Value").GetDouble();
var hasPrecip = conditions.GetProperty("HasPrecipitation").GetBoolean();
var isDayTime = conditions.GetProperty("IsDayTime").GetBoolean();

// Step 3: Display a formatted summary
Console.WriteLine("\nCurrent Conditions");
Console.WriteLine(new string('━', 42));
Console.WriteLine($"Conditions:    {weatherText}");
Console.WriteLine($"Temperature:   {tempF}°F / {tempC}°C");
Console.WriteLine($"Precipitation: {(hasPrecip ? "Yes" : "None")}");
Console.WriteLine($"Daytime:       {isDayTime}");
```

```java title="Java"
import org.json.JSONArray;
import org.json.JSONObject;
import java.net.URI;
import java.net.http.*;

public class CurrentConditions {
    public static void main(String[] args) throws Exception {
        String apiKey = "{YOUR_API_KEY}";
        String locationKey = "349727";

        // Step 1: Fetch current conditions
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(
                "https://apidev.accuweather.com/currentconditions/v1/"
                + locationKey + ".json?apikey=" + apiKey))
            .build();

        HttpResponse<String> response =
            client.send(request, HttpResponse.BodyHandlers.ofString());

        // Step 2: Parse the first item from the array
        var conditions = new JSONArray(response.body()).getJSONObject(0);

        String weatherText = conditions.getString("WeatherText");
        double tempF = conditions.getJSONObject("Temperature")
            .getJSONObject("Imperial").getDouble("Value");
        double tempC = conditions.getJSONObject("Temperature")
            .getJSONObject("Metric").getDouble("Value");
        boolean hasPrecip = conditions.getBoolean("HasPrecipitation");
        boolean isDayTime = conditions.getBoolean("IsDayTime");

        // Step 3: Display a formatted summary
        System.out.println("\nCurrent Conditions");
        System.out.println("━".repeat(42));
        System.out.println("Conditions:    " + weatherText);
        System.out.println("Temperature:   " + tempF + "°F / " + tempC + "°C");
        System.out.println("Precipitation: " + (hasPrecip ? "Yes" : "None"));
        System.out.println("Daytime:       " + isDayTime);
    }
}
```

```bash title="bash"
#!/bin/bash
API_KEY="{YOUR_API_KEY}"
LOCATION_KEY="349727"

# Step 1: Fetch current conditions
DATA=$(curl -s "https://apidev.accuweather.com/currentconditions/v1/${LOCATION_KEY}.json?apikey=${API_KEY}")

# Step 2: Parse the first item from the array
CONDITIONS=$(echo "$DATA" | jq '.[0]')

# Step 3: Display a formatted summary
WEATHER_TEXT=$(echo "$CONDITIONS" | jq -r '.WeatherText')
TEMP_F=$(echo "$CONDITIONS" | jq -r '.Temperature.Imperial.Value')
TEMP_C=$(echo "$CONDITIONS" | jq -r '.Temperature.Metric.Value')
HAS_PRECIP=$(echo "$CONDITIONS" | jq -r 'if .HasPrecipitation then "Yes" else "None" end')
IS_DAYTIME=$(echo "$CONDITIONS" | jq -r '.IsDayTime')

echo ""
echo "Current Conditions"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Conditions:    ${WEATHER_TEXT}"
echo "Temperature:   ${TEMP_F}°F / ${TEMP_C}°C"
echo "Precipitation: ${HAS_PRECIP}"
echo "Daytime:       ${IS_DAYTIME}"
```

</CodeTabs>

---

## Next steps

- [Hourly Forecast](/recipes/hourly-forecast) — plan ahead with hour-by-hour data
- [5-Day Daily Forecast](/recipes/daily-forecast) — multi-day high/low summaries
