get_orders
Retrieve store orders with filters for status, time period, and pagination. Use to manage and analyze sales data efficiently in CS-Cart.
Instructions
Retrieve orders from the CS-Cart store
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| items_per_page | No | Number of items per page | |
| page | No | Page number for pagination | |
| period | No | Time period filter (A=All time, D=Today, W=This week, M=This month, Y=This year) | |
| status | No | Order status filter (O=Open, P=Processed, C=Complete, F=Failed, D=Declined, B=Backordered, I=Incomplete) | |
| time_from | No | Start date for custom period (YYYY-MM-DD) | |
| time_to | No | End date for custom period (YYYY-MM-DD) | |
| user_id | No | Filter by user ID |
Implementation Reference
- src/index.js:501-517 (handler)The primary handler function for the 'get_orders' tool. It builds URL query parameters from input arguments and performs a GET request to the CS-Cart API's /orders endpoint via the makeRequest helper, returning a JSON-formatted response.async getOrders(args) { const params = new URLSearchParams(); if (args.page) params.append('page', args.page.toString()); if (args.items_per_page) params.append('items_per_page', args.items_per_page.toString()); if (args.status) params.append('status', args.status); if (args.period) params.append('period', args.period); if (args.time_from) params.append('time_from', args.time_from); if (args.time_to) params.append('time_to', args.time_to); if (args.user_id) params.append('user_id', args.user_id.toString()); const queryString = params.toString(); const endpoint = `/orders${queryString ? `?${queryString}` : ''}`; const result = await this.makeRequest('GET', endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }
- src/index.js:247-286 (schema)Input schema definition for the 'get_orders' tool, registered in the ListToolsRequestSchema handler. Defines parameters for pagination, status filtering, time periods, and user-specific queries.name: 'get_orders', description: 'Retrieve orders from the CS-Cart store', inputSchema: { type: 'object', properties: { page: { type: 'number', description: 'Page number for pagination', default: 1, }, items_per_page: { type: 'number', description: 'Number of items per page', default: 10, }, status: { type: 'string', description: 'Order status filter (O=Open, P=Processed, C=Complete, F=Failed, D=Declined, B=Backordered, I=Incomplete)', enum: ['O', 'P', 'C', 'F', 'D', 'B', 'I'], }, period: { type: 'string', description: 'Time period filter (A=All time, D=Today, W=This week, M=This month, Y=This year)', enum: ['A', 'D', 'W', 'M', 'Y'], }, time_from: { type: 'string', description: 'Start date for custom period (YYYY-MM-DD)', }, time_to: { type: 'string', description: 'End date for custom period (YYYY-MM-DD)', }, user_id: { type: 'number', description: 'Filter by user ID', }, }, }, },
- src/index.js:404-405 (registration)Registration/dispatch point in the CallToolRequestSchema switch statement, routing calls to the getOrders handler.case 'get_orders': return await this.getOrders(args);
- src/index.js:424-440 (helper)Shared helper method used by getOrders (and other tools) to make authenticated HTTP requests to the CS-Cart API using axios.async makeRequest(method, endpoint, data = null) { const config = { method, url: `${process.env.CSCART_API_URL}${endpoint}`, headers: { 'Content-Type': 'application/json', 'Authorization': `Basic ${Buffer.from(`${process.env.CSCART_API_EMAIL}:${process.env.CSCART_API_KEY}`).toString('base64')}`, }, }; if (data) { config.data = data; } const response = await axios(config); return response.data; }