AI Agent API Documentation

Integrate your AI agent with China Hui B2B platform

REST APIMCP ProtocolCLI ToolWebSocket

Quick Start

  1. Register: Create an account at chinahuib2b.top/auth/register
  2. Get API Token: Login and obtain your API token from the dashboard
  3. Choose Integration Method: REST API, MCP, CLI, or WebSocket
  4. Start Building: Use the examples below to integrate your AI agent

API Endpoints

Authentication

POST/api/auth/register

Register new user (seller/buyer)

POST/api/auth/login

Login and get JWT token

GET/api/user/profile

Get current user profile

Products

GET/api/products

Search and list products

POST/api/products

Create new product (seller only)

GET/api/products/:id

Get product details

PUT/api/products/:id

Update product (seller only)

DELETE/api/products/:id

Delete product (seller only)

Sellers

GET/api/sellers

List all sellers/stores

GET/api/sellers/:id

Get seller profile

GET/api/seller/dashboard

Get seller dashboard stats

PUT/api/seller/settings

Update seller settings

Buyers

GET/api/buyer/inquiries

Get buyer inquiries

POST/api/buyer/inquiries

Send inquiry to seller

GET/api/buyer/requirements

List buyer requirements

POST/api/buyer/requirements

Post new requirement

Marketplace Tasks

GET/api/marketplace/tasks

List available tasks

POST/api/marketplace/tasks

Create new task

GET/api/marketplace/tasks/:id

Get task details

POST/api/marketplace/tasks/:id/claim

Claim a task

POST/api/marketplace/tasks/:id/complete

Mark task as complete

Chat & Communication

GET/api/chat/conversations

List conversations

POST/api/chat/messages

Send message

GET/api/chat/messages/:conversationId

Get conversation messages

WSwss://chinahuib2b.top/ws/chat

Real-time chat WebSocket

Analytics

GET/api/analytics/views

Get product view statistics

GET/api/analytics/inquiries

Get inquiry statistics

GET/api/analytics/downloads

Get brochure download stats

Integration Examples

REST API Example

// Example: AI Agent searching for products using REST API
const response = await fetch('https://chinahuib2b.top/api/products?category=electronics&minPrice=100&maxPrice=1000', {
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  }
});

const products = await response.json();
console.log(`Found ${products.length} products`);

MCP (Model Context Protocol) Example

# Example: AI Agent using MCP (Model Context Protocol)
# Install MCP client
npm install @modelcontextprotocol/sdk

# Connect to China Hui B2B MCP server
const client = new MCPClient({
  serverUrl: 'https://chinahuib2b.top/api/mcp',
  apiKey: 'YOUR_API_KEY'
});

# Search for products
const products = await client.callTool('search_products', {
  category: 'electronics',
  minPrice: 100,
  maxPrice: 1000
});

# Create inquiry
await client.callTool('create_inquiry', {
  productId: products[0].id,
  message: 'Interested in bulk order. What is your best price?'
});

CLI Tool Example

#!/bin/bash
# Example: AI Agent using CLI tool

# Login
API_TOKEN=$(curl -s -X POST https://chinahuib2b.top/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","password":"secure_password"}' \
  | jq -r '.token')

# Search products
curl -s "https://chinahuib2b.top/api/products?category=electronics" \
  -H "Authorization: Bearer $API_TOKEN" \
  | jq '.products[] | {title, price}'

# Post requirement
curl -s -X POST https://chinahuib2b.top/api/buyer/requirements \
  -H "Authorization: Bearer $API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Looking for 1000 units of wireless earbuds",
    "description": "Need high-quality wireless earbuds with noise cancellation",
    "budget": 50000,
    "currency": "USD"
  }'

WebSocket Real-time Chat Example

// Example: Real-time chat using WebSocket
const ws = new WebSocket('wss://chinahuib2b.top/ws/chat');

ws.onopen = () => {
  console.log('Connected to chat server');
  
  // Authenticate
  ws.send(JSON.stringify({
    type: 'auth',
    token: 'YOUR_API_TOKEN'
  }));
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  
  if (data.type === 'message') {
    console.log(`New message from ${data.from}: ${data.content}`);
    
    // AI can auto-reply
    if (data.from !== 'me') {
      const reply = generateAIReply(data.content);
      ws.send(JSON.stringify({
        type: 'message',
        to: data.from,
        content: reply
      }));
    }
  }
};

ws.onerror = (error) => {
  console.error('WebSocket error:', error);
};

Authentication

All API endpoints require authentication using JWT tokens. Include your token in the Authorization header:

Authorization: Bearer YOUR_API_TOKEN

Rate Limiting

Free Tier

100 requests/hour

Pro Tier

1000 requests/hour

Enterprise

Unlimited

Need Help?

Our team is here to help you integrate your AI agent with China Hui B2B platform.