{"openapi":"3.1.0","info":{"title":"CommsGrid Messaging APIs","version":"1.0.0","description":"API reference for the CommsGrid SMS Gateway, Android Gateway, WhatsApp Cloud, and WhatsApp Web integrations. Use an active account and a plan that includes the module you are calling. SMS credits are billed separately. Keep API keys and account auth keys on your server and out of browser code."},"servers":[{"url":"\/","description":"Current CommsGrid host"}],"tags":[{"name":"SMS Gateway","description":"SMS through the configured SMS provider. Production sends consume paid SMS credits; sandbox keys use sandbox credits."},{"name":"Android Gateway","description":"SMS through a paired Android device. Requires active Android Gateway plan access and a connected device."},{"name":"Android companion app","description":"Pairing and device-to-server endpoints used by the Android Gateway companion app."},{"name":"WhatsApp Cloud","description":"Text message sending through a configured WhatsApp Cloud app."},{"name":"WhatsApp Web","description":"Sending through a QR-linked WhatsApp Web session. This is separate from the official WhatsApp Cloud API."}],"paths":{"\/api\/sms\/send":{"post":{"tags":["SMS Gateway"],"summary":"Send SMS messages","operationId":"sendSms","security":[{"bearerAuth":[]}],"description":"Send to one recipient or an array. The sender ID must be active and approved for this account. Production sends require SMS credits. Sandbox keys use sandbox credits and do not contact the live provider.","requestBody":{"required":true,"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/SmsSendRequest"},"example":{"recipient":"+254712345678","sender_id":"YOUR_ACTIVE_SENDER_ID","message":"Your message text"}}}},"responses":{"200":{"description":"Request processed; accepted recipients include message_id values for status checks.","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/StandardResponse"}}}},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"403":{"$ref":"#\/components\/responses\/Forbidden"},"429":{"$ref":"#\/components\/responses\/RateLimited"}}},"get":{"tags":["SMS Gateway"],"summary":"Send SMS (legacy GET form)","description":"Compatibility form. POST with a Bearer token is recommended. Avoid API keys in URLs because URLs can be recorded in logs.","operationId":"sendSmsLegacyGet","security":[{"bearerAuth":[]}],"parameters":[{"name":"recipient","in":"query","required":true,"schema":{"type":"string","description":"One number or comma-separated recipients."}},{"name":"sender_id","in":"query","required":true,"schema":{"type":"string"}},{"name":"message","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Request processed."},"400":{"$ref":"#\/components\/responses\/BadRequest"},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/sms\/balance":{"get":{"tags":["SMS Gateway"],"summary":"Get SMS balance","operationId":"getSmsBalance","security":[{"bearerAuth":[]},{"queryApiKey":[]}],"responses":{"200":{"description":"Balance, account ID, and sandbox or production environment."},"401":{"$ref":"#\/components\/responses\/Unauthorized"}}}},"\/api\/sms\/status\/{messageId}":{"get":{"tags":["SMS Gateway"],"summary":"Get SMS status","operationId":"getSmsStatus","security":[{"bearerAuth":[]},{"queryApiKey":[]}],"parameters":[{"$ref":"#\/components\/parameters\/MessageId"}],"responses":{"200":{"description":"Delivery status for a message owned by this account."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"404":{"description":"Message not found for this account."}}}},"\/api\/gateway\/send":{"post":{"tags":["Android Gateway"],"summary":"Send SMS through Android Gateway","operationId":"sendAndroidSms","security":[{"bearerAuth":[]}],"description":"The API key may be scoped to one device. Otherwise, device_id can select a connected device. recipient can be a string, array, or comma-separated list. send_at must be in the future and within 20 days; sim_slot is 0 or 1.","requestBody":{"required":true,"content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/AndroidSendRequest"},"example":{"recipient":"+254712345678","message":"Your message text","device_id":"DEVICE_UUID","sim_slot":0}}}},"responses":{"200":{"description":"Queued message IDs and, for multiple recipients, a batch_id."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"403":{"$ref":"#\/components\/responses\/Forbidden"},"422":{"description":"No connected device or device selection is invalid."}}},"get":{"tags":["Android Gateway"],"summary":"Send SMS (legacy GET form)","description":"Compatibility form; POST is recommended. Avoid API keys in URLs.","operationId":"sendAndroidSmsLegacyGet","security":[{"bearerAuth":[]},{"queryApiKey":[]}],"parameters":[{"name":"recipient","in":"query","required":true,"schema":{"type":"string"}},{"name":"message","in":"query","required":true,"schema":{"type":"string"}},{"name":"device_id","in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"Message queued."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"403":{"$ref":"#\/components\/responses\/Forbidden"}}}},"\/api\/gateway\/devices":{"get":{"tags":["Android Gateway"],"summary":"List available devices","operationId":"listAndroidDevices","security":[{"bearerAuth":[]},{"queryApiKey":[]}],"responses":{"200":{"description":"Device IDs, names, models, online status, battery, Android version, and last seen time."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"403":{"$ref":"#\/components\/responses\/Forbidden"}}}},"\/api\/gateway\/status\/{messageId}":{"get":{"tags":["Android Gateway"],"summary":"Get Android message status","operationId":"getAndroidMessageStatus","security":[{"bearerAuth":[]},{"queryApiKey":[]}],"parameters":[{"$ref":"#\/components\/parameters\/MessageId"}],"responses":{"200":{"description":"Message status and device details."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"404":{"description":"Message not found."}}}},"\/api\/gateway\/bulk\/{batchId}":{"get":{"tags":["Android Gateway"],"summary":"Get batch status","operationId":"getAndroidBatchStatus","security":[{"bearerAuth":[]},{"queryApiKey":[]}],"parameters":[{"name":"batchId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"Total, pending, sent, failed counts and each message's status."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"404":{"description":"Batch not found."}}}},"\/api\/android-gateway\/register":{"post":{"tags":["Android companion app"],"summary":"Pair Android device","description":"Exchange the pairing token shown in the account dashboard for a device token. Rate limited.","operationId":"registerAndroidDevice","requestBody":{"required":true,"content":{"application\/json":{"schema":{"type":"object","required":["pairing_token"],"properties":{"pairing_token":{"type":"string"},"device_name":{"type":"string","maxLength":100},"model":{"type":"string","maxLength":100},"android_version":{"type":"string","maxLength":50},"fcm_token":{"type":"string","maxLength":512},"e2e_key":{"type":"string","maxLength":64}}}}}},"responses":{"200":{"description":"Returns device_token and phone_id."},"404":{"description":"Pairing token is invalid or expired."},"422":{"$ref":"#\/components\/responses\/BadRequest"}}}},"\/api\/android-gateway\/version":{"get":{"tags":["Android companion app"],"summary":"Check companion app version","operationId":"getAndroidAppVersion","responses":{"200":{"description":"Returns latest published app version details."}}}},"\/api\/android-gateway\/pending":{"get":{"tags":["Android companion app"],"summary":"Fetch queued messages for device","operationId":"getAndroidPendingMessages","security":[{"deviceBearer":[]}],"responses":{"200":{"description":"Pending messages for the authenticated device."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"403":{"$ref":"#\/components\/responses\/Forbidden"}}}},"\/api\/android-gateway\/status":{"post":{"tags":["Android companion app"],"summary":"Report delivery status","operationId":"reportAndroidMessageStatus","security":[{"deviceBearer":[]}],"requestBody":{"required":true,"content":{"application\/json":{"schema":{"type":"object","required":["message_id","status"],"properties":{"message_id":{"type":"string"},"status":{"type":"string","enum":["sent","delivered","failed"]},"failure_reason":{"type":"string","maxLength":255}}}}}},"responses":{"200":{"description":"Status recorded."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"404":{"description":"Message is not assigned to this device."},"422":{"$ref":"#\/components\/responses\/BadRequest"}}}},"\/api\/android-gateway\/heartbeat":{"post":{"tags":["Android companion app"],"summary":"Update device heartbeat","operationId":"androidDeviceHeartbeat","security":[{"deviceBearer":[]}],"requestBody":{"content":{"application\/json":{"schema":{"type":"object","properties":{"battery_level":{"type":"integer"},"fcm_token":{"type":"string"},"sim_info":{"type":"object"},"heartbeat_interval_minutes":{"type":"integer"}}}}}},"responses":{"200":{"description":"Current device status."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"403":{"$ref":"#\/components\/responses\/Forbidden"}}}},"\/api\/android-gateway\/inbound":{"post":{"tags":["Android companion app"],"summary":"Report received SMS","operationId":"reportAndroidInboundSms","security":[{"deviceBearer":[]}],"requestBody":{"required":true,"content":{"application\/json":{"schema":{"type":"object","required":["received_at","fingerprint"],"properties":{"sender":{"type":"string","maxLength":32},"message":{"type":"string"},"received_at":{"type":"integer","description":"Unix timestamp in milliseconds."},"fingerprint":{"type":"string","maxLength":255},"sim_slot":{"type":"integer"},"message_ciphertext":{"type":"string"},"message_iv":{"type":"string"}}}}}},"responses":{"201":{"description":"Inbound SMS recorded."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"403":{"$ref":"#\/components\/responses\/Forbidden"},"422":{"$ref":"#\/components\/responses\/BadRequest"}}}},"\/api\/whatsapp\/device\/{uuid}\/webhook":{"get":{"tags":["WhatsApp Cloud"],"summary":"Verify a WhatsApp Cloud webhook","description":"Meta calls this endpoint when registering a webhook. The verify token must match the platform UUID configured in CommsGrid.","operationId":"verifyWhatsAppCloudWebhook","parameters":[{"name":"uuid","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"hub.mode","in":"query","required":true,"schema":{"type":"string","enum":["subscribe"]}},{"name":"hub.verify_token","in":"query","required":true,"schema":{"type":"string","description":"Must match the configured platform UUID."}},{"name":"hub.challenge","in":"query","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Returns the challenge as plain text.","content":{"text\/plain":{"schema":{"type":"string"}}}},"403":{"description":"The mode, verify token, or platform is invalid."}}},"post":{"tags":["WhatsApp Cloud"],"summary":"Receive WhatsApp Cloud webhook events","description":"Meta posts account and message events to this platform-specific URL. Unknown platform UUIDs are acknowledged with HTTP 200 and are not processed.","operationId":"receiveWhatsAppCloudWebhook","parameters":[{"name":"uuid","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"required":true,"content":{"application\/json":{"schema":{"type":"object","description":"WhatsApp Business Account webhook event payload."}}}},"responses":{"200":{"description":"Webhook acknowledged."}}}},"\/api\/whatsapp\/message":{"post":{"tags":["WhatsApp Cloud"],"summary":"Send WhatsApp Cloud text message","description":"Requires a configured Cloud app, matching owner auth key, connected platform, and active WhatsApp plan. This documents the current text-message request accepted by the code.","operationId":"sendWhatsAppCloudMessage","requestBody":{"required":true,"content":{"application\/json":{"schema":{"type":"object","required":["appkey","authkey","to","message"],"properties":{"appkey":{"type":"string"},"authkey":{"type":"string","description":"Account auth key. Keep secret."},"to":{"type":"string","description":"Recipient number in international format."},"message":{"type":"string"}}},"example":{"appkey":"YOUR_APP_KEY","authkey":"YOUR_ACCOUNT_AUTH_KEY","to":"+254712345678","message":"Hello from CommsGrid"}}}},"responses":{"200":{"description":"Provider message ID and status."},"403":{"$ref":"#\/components\/responses\/Forbidden"},"422":{"description":"Invalid request."},"500":{"description":"Application or provider error."}}}},"\/api\/whatsapp-web\/send-message":{"post":{"tags":["WhatsApp Web"],"summary":"Send WhatsApp Web message","description":"Sends through the QR-linked WhatsApp Web app. app_key must belong to the user identified by auth_key, who must have active WhatsApp Web entitlement. For media types, url must be publicly reachable.","operationId":"sendWhatsAppWebMessage","requestBody":{"required":true,"content":{"application\/json":{"schema":{"type":"object","required":["app_key","auth_key","to","message"],"properties":{"app_key":{"type":"string"},"auth_key":{"type":"string","description":"Account auth key. Keep secret."},"to":{"type":"string","description":"Recipient number without a WhatsApp JID suffix."},"type":{"type":"string","enum":["text","image","audio","video","document"],"default":"text"},"message":{"type":"string","maxLength":1000,"description":"Required for text messages."},"url":{"type":"string","format":"uri","description":"Required for image, audio, video, and document messages."}}},"example":{"app_key":"YOUR_APP_KEY","auth_key":"YOUR_ACCOUNT_AUTH_KEY","to":"+254712345678","type":"text","message":"Hello from CommsGrid"}}}},"responses":{"200":{"description":"Returns WhatsApp service response."},"401":{"$ref":"#\/components\/responses\/Unauthorized"},"403":{"$ref":"#\/components\/responses\/Forbidden"},"404":{"description":"WhatsApp platform not found."},"422":{"$ref":"#\/components\/responses\/BadRequest"}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API key","description":"Use an active module API key as Authorization: Bearer YOUR_API_KEY. SMS and Android Gateway keys are managed separately. The APIs also accept a query api_key for compatibility; prefer the header."},"queryApiKey":{"type":"apiKey","in":"query","name":"api_key","description":"Compatibility option for GET endpoints only. Prefer Authorization: Bearer because URLs can be logged."},"deviceBearer":{"type":"http","scheme":"bearer","bearerFormat":"Device token","description":"Use the device_token returned by \/api\/android-gateway\/register as Authorization: Bearer DEVICE_TOKEN."}},"parameters":{"MessageId":{"name":"messageId","in":"path","required":true,"schema":{"type":"string"},"description":"Message ID returned by a send endpoint."}},"responses":{"BadRequest":{"description":"Invalid request or insufficient credits.","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/StandardResponse"}}}},"Unauthorized":{"description":"Missing, invalid, or inactive credentials.","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/StandardResponse"}}}},"Forbidden":{"description":"Inactive account or inactive module entitlement.","content":{"application\/json":{"schema":{"$ref":"#\/components\/schemas\/StandardResponse"}}}},"RateLimited":{"description":"Rate limit exceeded.","headers":{"Retry-After":{"schema":{"type":"integer"}}}}},"schemas":{"SmsSendRequest":{"type":"object","required":["recipient","sender_id","message"],"properties":{"recipient":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}],"description":"One or more Kenyan phone numbers."},"sender_id":{"type":"string"},"message":{"type":"string"}}},"AndroidSendRequest":{"type":"object","required":["recipient","message"],"properties":{"recipient":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}],"description":"One number, an array, or comma-separated numbers."},"message":{"type":"string","maxLength":1600},"device_id":{"type":"string"},"send_at":{"type":"string","format":"date-time"},"sim_slot":{"type":"integer","enum":[0,1]}}},"StandardResponse":{"type":"object","properties":{"status":{"type":"string","enum":["success","error"]},"message":{"type":"string"},"data":{"type":["object","array","null"],"additionalProperties":true}}}}}}