API reference

Realtime

The dashboard and any Socket.io client can receive live QR codes, session status, inbox messages, campaign progress, and in-app notifications without polling REST.

Connect to `https://api.actiwapi.com` with the same JWT you use for REST. After connect, join a session room to receive QR and per-session message events.

Connect with JWT

Use the official socket.io-client. Pass the access token in handshake.auth.token (query.token is also accepted). Invalid or expired tokens close the handshake with “Invalid or expired token”.

  • URL: https://api.actiwapi.com (same host as the REST API, not /api).
  • transports: websocket first, polling fallback.
  • On success the server emits connected with { userId, tenantId, events }.
  • The socket automatically joins tenant:{tenantId} and user:{userId}.

Subscribe to a session

QR codes and per-session inbound/outbound events are sent to session:{tenantId}:{sessionId}. Emit subscribe:session with the session UUID after connect (subscribe:account is an alias). Unsubscribe with unsubscribe:session.

Server events

These names are canonical. Payloads always include a timestamp when the server emits them.

  • qr_generated — { sessionId, qr } while pairing. Render the QR in your UI.
  • session_connected / session_disconnected / session_status_update — connection lifecycle.
  • message_received / message_sent — inbox and outbound pipeline.
  • campaign_started / campaign_completed — bulk send lifecycle.
  • notification_new — in-app notification for the user or whole tenant.

Webhooks are the right choice for backend automation. Socket.io is for interactive UIs. Do not put the JWT in a public browser app that untrusted users can inspect.

Minimal client

Install socket.io-client, connect with your JWT, subscribe to the session you are pairing, then listen for qr_generated.

  • io(SOCKET_URL, { auth: { token: accessToken } })
  • socket.on("connected", handler)
  • socket.emit("subscribe:session", sessionId)
  • socket.on("qr_generated", ({ qr }) => { /* render QR image */ })

Error codes

Failed requests return a JSON envelope with success: false and a human-readable message.

{
  "success": false,
  "message": "Validation failed",
  "errors": {
    "phone": "Valid phone number is required"
  }
}
HTTPCodeDescription
400VALIDATION_ERRORRequest body or query failed validation.
401UNAUTHORIZEDMissing or invalid JWT / API key.
403FORBIDDENAuthenticated but lacking permission or entitlement.
403SUBSCRIPTION_INACTIVEAction not allowed on the current plan (including Free after trial). Upgrade or wait for entitlements.
403LIMIT_EXCEEDEDPlan limit reached (sessions, messages, API requests, etc.).
404NOT_FOUNDResource does not exist or is not in your account.
409CONFLICTDuplicate resource or invalid state transition.
429RATE_LIMITEDToo many requests; retry after backoff.
500INTERNAL_ERRORUnexpected server error.
502WHATSAPP_UNAVAILABLEWhatsApp session disconnected or provider error.