> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# WattTime

> Client-mode REST API connector for a curated WattTime v3 slice: login and read a region forecast

Technical Preview

# WattTime

Client-mode REST API connector for a curated WattTime v3 slice: login and read a region forecast.

* Hub category: **Energy**.
* Base: `https://api.watttime.org`

## Template reference

Generated from the shipped broker template `watttime` (`-routeCode WATTTIME`). It lists every event the template defines.

### Auth

Auth headers used by the template: `Authorization: Bearer {value.json.api_token}`.

### Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the WattTime connector | no |
| `BaseUrl` | string | WattTime base URL without trailing slash (e.g. [https://api.watttime.org](https://api.watttime.org)) | yes |

`BASE_ADDRESS` default: `https://api.watttime.org`.

### Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `Login` | POST | `/v3/login` | `energy/watttime/login` | `energy/watttime/login/response` | `api_token`, `body` |
| `Getforecast` | GET | `/v3/forecast?region={value.json.region}&signal_type=co2_moer` | `energy/watttime/forecast` | `energy/watttime/forecast/response` | `api_token`, `region` |

### Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-routeCode WATTTIME"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
DEFINE ROUTE WattTimeRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://api.watttime.org"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Login
        WITH SOURCE_TOPIC "energy/watttime/login"
        WITH DESTINATION_TOPIC "energy/watttime/login/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/v3/login"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
        WITH BODY "{value.json.body}"
    ADD EVENT Getforecast
        WITH SOURCE_TOPIC "energy/watttime/forecast"
        WITH DESTINATION_TOPIC "energy/watttime/forecast/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/v3/forecast?region={value.json.region}&signal_type=co2_moer"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
```

Deploy it with `-addRoute` (do not include `ADD METADATA`).

### Usage example

Call `Login` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'energy/watttime/login/response' &
mosquitto_pub -t 'energy/watttime/login' -m '{"api_token": "<api_token>", "body": {}}'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.