Beginner

API, Webhook, JSON and Endpoint Explained

These words appear everywhere in bot projects. They describe different parts of the same conversation between programs.

Illustration of code, API warnings and a trading bot
Illustration: API, webhook and JSON errors become easier when each layer is checked separately.

The shortest explanation

An API is the rules for talking to a service. An endpoint is a specific API address. A request is a message sent to that address. A webhook is an incoming request triggered by an event. JSON is a common format for the data inside the request.

Think of an API as a menu

A restaurant menu tells you what can be ordered and how to ask for it. An API does the same for software. Documentation might define an endpoint for prices, another for positions and another for placing orders. Each endpoint defines which HTTP method to use, what authentication is needed, what fields are accepted and what response comes back.

GET  /api/positions      -> ask for current positions
POST /api/order          -> send a new order request
DELETE /api/order/123    -> request cancellation

HTTP methods are verbs

GET usually retrieves data. POST usually sends or creates something. PUT/PATCH often update. DELETE usually removes or cancels. These are conventions, not guarantees; the API documentation is authoritative.

An endpoint is an address with a job

If a Worker lives at https://example.com/api/webhook, that URL can be an endpoint. The path /api/webhook distinguishes it from /api/health or /api/tips. A good service gives each endpoint a narrow responsibility.

A webhook is event-driven

Polling means your program repeatedly asks for changes. A webhook means the source calls you when something happens. This can reduce delay and unnecessary requests, but it means your endpoint is publicly reachable and must verify who is allowed to call it.

TradingView
  event occurs
     ↓
POST https://example.com/api/webhook
     ↓
Your receiver validates the message
     ↓
Your internal bot logic runs

JSON labels the data

Without structure, a message such as BTCUSD BUY 0.01 requires custom parsing. JSON makes each value explicit.

{
  "event_id": "evt-001",
  "symbol": "BTCUSD",
  "action": "buy",
  "size": 0.01,
  "dry_run": true
}

Quotes matter. "0.01" is text; 0.01 is a number. true is a boolean; "true" is text. A receiver should validate types instead of assuming they are correct.

What a robust receiver checks

Status codes tell the sender what happened

CodeMeaning in plain EnglishTypical bot example
200 / 201Accepted/succeededEvent saved or action completed
400Bad requestMalformed JSON or missing required field
401 / 403Not authenticated / not allowedWrong secret or forbidden origin
404Endpoint not foundWrong URL path
409ConflictDuplicate event ID
429Too many requestsRate limit reached
500Server-side errorUnhandled backend failure

Common beginner mistakes

Useful mental model: external input is untrusted. Parse it, validate it, normalize it into your own small internal event format, and only then let business logic use it.