Quick start
This page walks you through the ExpTech API in as few steps as possible. Call an HTTP API that needs no auth, create an API Token, then open a real-time stream. Before you start, read the Usage rules and the Terms of Service.
-
Call your first API
Earthquake reports do not need a token right now. This fetches the 5 most recent CWA earthquake reports:
終端機視窗 curl -sL "https://api.core.exptech.dev/api/v2/eq/report?limit=5"const res = await fetch("https://api.core.exptech.dev/api/v2/eq/report?limit=5");if (!res.ok) throw new Error(`HTTP ${res.status}`);const reports = await res.json();console.log(reports[0].loc, reports[0].mag);The response is a JSON array. Each item is one earthquake report. Field descriptions are on Earthquake reports.
Other hosts and nodes are on Servers and Base URL. Before you go to production, prepare backup hosts in the client as that page describes.
-
Create an API Token
APIs that require auth, and streams that record usage, need an API Token:
- Sign in at https://manager.exptech.com.tw/login (enter your email, then open the sign-in link in the message).
- On the dashboard, open the API Tokens page, choose permissions, and create a token.
- The token is shown only once. Save it immediately. It is a string that starts with
et_.
What each permission means: Permissions. How to send a token and how to revoke one: API Token.
-
Open a real-time stream
Real-time data is sent as SSE (Server-Sent Events). This connects to the earthquake report stream
eq.report.v1. When a new earthquake report is available, the server pushes a message.終端機視窗 curl -N -H "Authorization: Bearer et_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \"https://api.lb.exptech.dev/api/v1/trem/sse/report"The browser
EventSourcecannot set headers, so put the token in the query string. Each message is gzip-compressed, then base64-encoded. Decode it first:const token = "et_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";const es = new EventSource(`https://api.lb.exptech.dev/api/v1/trem/sse/report?token=${encodeURIComponent(token)}`,);async function decode(base64) {const bytes = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream("gzip"));return JSON.parse(await new Response(stream).text());}es.onmessage = async (event) => {console.log(await decode(event.data));};eq.report.v1is a public topic. You can connect without a token. If you send a token, usage is counted on your account. View it under Usage on the dashboard. A topic that requires a permission needs a token with that permission, and the account must have subscribed to that resource under Subscriptions on the dashboard. Otherwise the connection is rejected. How subscriptions and quotas are counted: Usage and quota.The opening
event: info, the heartbeat every 60 seconds, how several topics share one connection, and how to reconnect are covered in Real-time streams. -
Next steps
- Servers and Base URL: host groups and failover
- Real-time streams: available topics and data formats
- Map tiles, Weather, Disaster information (DPIP): other data APIs
- Error codes: status codes and why a stream disconnects
- OAuth2: let your app get authorization on a user’s behalf
