API libraries
You can call the Ha Tang REST API from any language with a plain HTTP client. This page lists the official libraries that make it easier, and shows how to generate a typed client from the OpenAPI spec for languages without an official SDK.
Node.js: @hatang/sdk
The official server SDK covers Email, Support, Products, CRM, Payments and e-invoices, with TypeScript types for every request and response.
npm install @hatang/sdk
import { Hatang } from "@hatang/sdk";
const hatang = new Hatang(process.env.HATANG_API_KEY, {
baseUrl: "https://api.hatang.dev",
// environment: "development", // Payments only; sent as Hatang-Environment
});
const { data, error } = await hatang.emails.send({
subject: "Welcome",
html: "<p>Welcome to the shop!</p>",
});
What to know:
- Results, not exceptions. Every method resolves to
{ data, error }and never throws for API errors.errorhas the usualstatusCode,nameandmessage(Errors). A network failure givesstatusCode: 0. - Configuration. Pass the key and options to the constructor, or set
HATANG_API_KEY,HATANG_BASE_URLandHATANG_ENVIRONMENT. Always set the base URL tohttps://api.hatang.dev. - Namespaces follow the API:
emails,batch,domains,templates,contacts,contactProperties,audiences,segments,topics,broadcasts,automations,events,apiKeys,webhooks,logs,usage,chat,paymentsandeinvoices. - Idempotency. Methods that create things take an
{ idempotencyKey }option (Idempotency). - Webhook helpers.
verifyWebhookandconstructWebhookEventcheck webhook signatures;verifyIpnandconstructIpnEventcheck Payments IPN calls (Webhooks). - React Email. Pass a
reactelement toemails.sendand the SDK renders it to HTML and plain text (install@react-email/renderandreactalongside).
The Node.js SDK guide covers every namespace with examples.
Chat SDKs for web and mobile
The chat SDKs run in your visitors' browsers and apps. They connect to the chat gateway with a public site id (and an app key on mobile), never with an API key.
| Platform | Package |
|---|---|
| Website | https://chat.hatang.dev/widget.js |
| React / Next.js | @hatang/chat-react |
| WordPress | Ha Tang Chat plugin |
| Flutter | hatang_chat |
| React Native / Expo | @hatang/chat-react-native |
| iOS (Swift) | HatangChat |
| Android (Kotlin) | dev.hatang:chat |
The SDK overview links the guide for each, the supported versions and the realtime protocol they share.
Other languages
There is no official server SDK for PHP, Python or Go yet. Two good options:
- Call the REST API directly. Every guide in this hub has cURL, Python and PHP samples. The API is plain JSON over HTTPS with a Bearer token.
- Generate a client from the OpenAPI spec, as below.
The OpenAPI spec
The REST API is described by an OpenAPI 3.1 document, generated from the same code that serves the API:
| Spec | URL |
|---|---|
| REST API | https://api.hatang.dev/openapi.json |
| Chat gateway | https://chat.hatang.dev/openapi.json |
Browse it in the REST API reference and the chat gateway reference, or import it into an API client such as Postman or Insomnia to try calls by hand.
Generate a client
Point a generator at the spec URL. Some examples:
# TypeScript types (use them with openapi-fetch or your own fetch wrapper)
npx openapi-typescript https://api.hatang.dev/openapi.json -o hatang.d.ts
# Python
pipx run openapi-python-client generate --url https://api.hatang.dev/openapi.json
# Many languages, including PHP, Java, Kotlin, C# and Ruby
npx @openapitools/openapi-generator-cli generate \
-i https://api.hatang.dev/openapi.json -g php -o ./hatang-php
The spec uses OpenAPI 3.1. Check that your generator supports 3.1; some only handle 3.0 fully. Regenerate the client when you upgrade, as new endpoints and fields are added to the spec as they ship.
Generated clients send what you give them, so remember the shared rules: the Authorization: Bearer header, Idempotency-Key on sends and payments, pagination with after, and retries on 429 (Rate limits).