erp_cari_olustur
Create a new customer card in the ERP system, providing essential details such as customer code, name, tax number, and status. Generates a direct link for easy access to the created customer record.
Instructions
ERP sisteminde yeni cari kartı oluşturur. oluşturdukdan sonra kullanıcıya bu linki verebilir https://erp.aaro.com.tr/Cari/Kalem?id={id}
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| CariAdi | Yes | Cari adı (zorunlu) | |
| CariKodu | Yes | Cari kodu (zorunlu) | |
| Durum | No | Aktif/Pasif durumu (varsayılan: true) | |
| SirketID | No | Şirket ID (varsayılan: 1) | |
| SubeID | No | Şube ID (varsayılan: 1) | |
| TipID | No | Cari tipi (varsayılan: 2001) | |
| VergiDairesiID | No | Vergi dairesi ID | |
| VergiNo | No | Vergi numarası |
Implementation Reference
- src/index.ts:433-457 (handler)Handler function that implements the logic for creating a new 'Cari' (ERP customer/vendor account). Validates required fields, constructs the data payload with defaults, and invokes the ERP API at '/api/Cari' via POST.private async createCari(args: any) { const { CariKodu, CariAdi, VergiNo, VergiDairesiID, TipID, SubeID, SirketID, Durum, ...otherParams } = args; if (!CariKodu || !CariAdi) { throw new Error('CariKodu ve CariAdi gerekli'); } const cariData = { CariID: -1, // Yeni kayıt için -1 CariKodu, CariAdi, VergiNo: VergiNo || '', VergiDairesiID: VergiDairesiID || null, TipID: TipID || '2001', // Varsayılan cari tipi SubeID: SubeID || '1', SirketID: SirketID || '1', Durum: Durum !== undefined ? Durum : true, ...otherParams }; return await this.callErpApi('/api/Cari', 'POST', { KayitTipi: '1', // Yeni kayıt body: cariData }); }
- src/index.ts:238-239 (registration)Registration/dispatch point in callSpecialHandler switch statement that routes calls to the createCari handler function. This is triggered when the tool config specifies handler: 'createCari' (likely for tool name 'erp_cari_olustur').case 'createCari': return await this.createCari(args);
- src/index.ts:692-800 (helper)Helper function used by createCari to make authenticated API calls to the ERP system, handling token management, headers, and error handling.private async callErpApi(endpoint: string, method: 'GET' | 'POST', args: any) { try { // Token'ı otomatik olarak al (cache'den veya yeni) let token = this.getCachedToken(); if (!token) { this.log('Token bulunamadı, yeni token alınıyor...'); token = await this.getErpToken(); } // URL'nin harici olup olmadığını kontrol et const isExternalUrl = endpoint.startsWith('http://') || endpoint.startsWith('https://'); const finalUrl = isExternalUrl ? endpoint : `${this.settings.erp.baseUrl}${endpoint}`; const config: any = { method, url: finalUrl, headers: { 'Authorization': `Bearer ${encodeURIComponent(token)}`, ...this.settings.api.defaultHeaders, }, timeout: this.settings.api.timeout, }; // Harici URL için ek header'lar ekle if (isExternalUrl) { config.headers['X-Original-ERP-URL'] = `${this.settings.erp.baseUrl}${endpoint.replace(/^https?:\/\/[^\/]+/, '')}`; config.headers['X-ERP-Token'] = encodeURIComponent(token); } if (method === 'GET') { // Tüm parametreleri query string olarak ekle const queryParams = { ...args }; delete queryParams.endpoint; delete queryParams.method; delete queryParams.body; if (Object.keys(queryParams).length > 0) { config.params = queryParams; } } else if (method === 'POST') { if (args.body) { config.data = args.body; } // POST için query parametreleri de ekle const queryParams = { ...args }; delete queryParams.endpoint; delete queryParams.method; delete queryParams.body; if (Object.keys(queryParams).length > 0) { config.params = queryParams; } } this.log(`API çağrısı: ${method} ${endpoint}`, 'info', { url: config.url, method: config.method, params: config.params, isExternal: isExternalUrl }); const response = await axios(config); this.log(`API başarılı: ${method} ${endpoint}`, 'info', { status: response.status, dataLength: JSON.stringify(response.data).length, isExternal: isExternalUrl }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { let errorMessage = 'Bilinmeyen hata'; if (axios.isAxiosError(error)) { if (error.response) { errorMessage = `HTTP ${error.response.status}: ${error.response.statusText}`; if (error.response.data) { errorMessage += `\n${JSON.stringify(error.response.data, null, 2)}`; } } else if (error.request) { errorMessage = 'İstek gönderildi ancak yanıt alınamadı'; } else { errorMessage = error.message; } } else if (error instanceof Error) { errorMessage = error.message; } this.log(`API hatası: ${method} ${endpoint}`, 'error', { error: errorMessage }); return { content: [ { type: 'text', text: `API Hatası: ${errorMessage}`, }, ], isError: true, }; } }
- src/index.ts:166-174 (registration)Dynamic tool registration/listing handler that exposes tools from config/tools.json, including likely 'erp_cari_olustur' with its schema and description.this.server.setRequestHandler(ListToolsRequestSchema, async () => { const tools = Object.entries(this.toolsConfig).map(([name, config]) => ({ name, description: config.description, inputSchema: config.inputSchema, })); return { tools }; });