REST API
ShopChat registers a REST API namespace (/wp-json/shopchat/v1/) for the widget's communication.
Endpoints
| Endpoint | Method | Description |
|---|---|---|
/wp-json/shopchat/v1/chat | POST | Send a chat message; returns AI response |
/wp-json/shopchat/v1/products | GET | Search products by query string |
/wp-json/shopchat/v1/kb | GET | Search knowledge base by query string |
Chat Request
Endpoint: POST /wp-json/shopchat/v1/chat
{
"message": "Do you have running shoes under $80?",
"session_id": "abc123",
"context": []
}Response:
{
"reply": "Yes! Here are some options under $80...",
"products": [
{
"id": 42,
"name": "TrailRunner Pro",
"price": "$74.99",
"url": "https://example.com/product/trailrunner-pro/",
"image": "https://example.com/wp-content/uploads/trailrunner.jpg"
}
],
"handoff": false
}Authentication
All REST endpoints require nonce authentication from the widget (automatically handled by the JavaScript widget).
External API access requires a custom authentication scheme via the shopchat_rest_auth filter:
add_filter( 'shopchat_rest_auth', function( bool $allowed, WP_REST_Request $request ): bool {
// Implement your own auth logic.
return $allowed;
}, 10, 2 );Do not expose ShopChat REST endpoints without authentication to external clients - they carry conversation context that may include customer data.