# Statistics, exchange rates and weather

## SSB — the three-step workflow

Statistics Norway publishes 6 000+ tables. They are not 6 000 operations; they
are **one parameter** on three operations. That means you must find and inspect
a table before you can query it.

### 1. Find the table

```
norsk_call(id="ssb.tabell.search", params={query:"konsumprisindeks"}, limit=5)
```

Norwegian keywords work far better than English — SSB's own metadata is
Norwegian. Try `befolkning` (population), `lønn` (wages), `boligpris` (house
prices), `arbeidsledighet` (unemployment), `konsumprisindeks` (CPI).

Returns a `tabell` id (e.g. `03013`). **Use that value verbatim** — it is already
extracted from the title for you.

### 2. Inspect its dimensions

```
norsk_call(id="ssb.tabell.metadata", params={tabell:"03013"})
```

Every SSB table is an n-dimensional cube. This returns the variable ids and a
sample of valid codes for each, e.g.:

```
Konsumgrp      konsumgruppe        339 codes   TOTAL = Totalindeks, 01 = Matvarer...
ContentsCode   statistikkvariabel    4 codes   KpiIndMnd = Konsumprisindeks (2015=100)...
Tid            måned               564 codes   1979M01, 1979M02, ...
```

Long code lists are sampled, not dumped — `antallKoder` tells you the true size.
**Every variable listed is mandatory** in the query.

### 3. Query it

```
norsk_call(id="ssb.tabell.data", params={
  tabell:"03013",
  valgKoder:"Konsumgrp=TOTAL&ContentsCode=KpiIndMnd&Tid=top(5)"
})
```

`valgKoder` is one flat string: `Variabel=kode&Variabel2=kode`. Selectors:

- `top(n)` — the n most recent values. **Use this for time**, almost always.
- `*` — every code. Dangerous on a 564-code dimension; you will hit the token
  budget and get truncated.
- `A,B,C` — an explicit list.

Results come back as flat labelled rows, one per cell, with a `value`.

### Skipping step 2

You can, if you already know the variable ids from a previous call in the same
conversation. Do not guess them — a wrong variable name returns a 400 that costs
you the same call you were trying to save.

## Norges Bank — exchange rates

```
norsk_call(id="norgesbank.kurs.get", params={valuta:"USD", antall:5})
```

Official published rates, newest last. `frekvens`: `B` business-daily (default),
`M` monthly average, `A` annual average.

Rates are **NOK per unit of the base currency** — a `kurs` of 9.4225 for USD
means 1 USD = 9.4225 NOK. Watch `multiplikator` (UNIT_MULT): for currencies
quoted per 100 units (JPY, ISK) it is non-zero and the rate is per 100, not
per 1.

There is no rate for a weekend or holiday. Asking for "today" near a weekend
correctly returns the last business day — quote the `dato` you actually got,
don't imply it is today's.

## MET — weather

```
norsk_call(id="met.varsel.get", params={lat:59.91, lon:10.75}, limit=12)
```

One row per hour: temperature °C, wind m/s, precipitation mm in the next hour,
and a symbol code. The raw forecast is ~38 KB covering nine days; the default
limit of 10 gives you the next 10 hours, which is what most questions need.

Need a place rather than a coordinate? Geocode first with
`kartverket.adresse.search` or `kartverket.stedsnavn.search`, then pass the
lat/lon through.
