Connecting global buyers and sellers, start from "discovery" | We are a B2B platform founded by Chinese entrepreneurs | We believe every merchant should have the opportunity to showcase their factory, brand, and goods to the world | This platform is only used for supply and demand information display and matching

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 x2xhub.com/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://x2xhub.com/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://x2xhub.com/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://x2xhub.com/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://x2xhub.com/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"[email protected]","password":"secure_password"}' \
  | jq -r '.token')

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

# Post requirement
curl -s -X POST https://x2xhub.com/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://x2xhub.com/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.