-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
102 lines (88 loc) · 3.58 KB
/
Copy pathexample.js
File metadata and controls
102 lines (88 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import N8nClient from './n8n-client.js';
// إنشاء instance من المكتبة
const n8n = new N8nClient();
/**
* أمثلة استخدام مكتبة n8n API
*/
async function examples() {
try {
console.log('🚀 بدء أمثلة استخدام n8n API...\n');
// 1. اختبار الاتصال
console.log('1️⃣ اختبار الاتصال بـ n8n...');
const isConnected = await n8n.testConnection();
console.log(` ✅ الاتصال: ${isConnected ? 'نجح' : 'فشل'}\n`);
// 2. جلب جميع workflows
console.log('2️⃣ جلب جميع workflows...');
const workflows = await n8n.getAllWorkflows();
console.log(` ✅ تم العثور على ${workflows.length} workflow\n`);
// 3. عرض workflows
if (workflows.length > 0) {
console.log('3️⃣ عرض workflows:');
workflows.slice(0, 5).forEach((workflow, index) => {
console.log(` ${index + 1}. ${workflow.name} (ID: ${workflow.id}) - ${workflow.active ? '✅ نشط' : '❌ غير نشط'}`);
});
console.log();
}
// 4. جلب workflow محدد (إذا كان هناك workflows)
if (workflows.length > 0) {
const firstWorkflow = workflows[0];
console.log(`4️⃣ جلب تفاصيل workflow: ${firstWorkflow.name}...`);
const workflowDetails = await n8n.getWorkflow(firstWorkflow.id);
console.log(` ✅ تم جلب التفاصيل: ${workflowDetails.name}\n`);
}
// 5. جلب executions
console.log('5️⃣ جلب آخر executions...');
const executions = await n8n.getExecutions({ limit: 5 });
console.log(` ✅ تم العثور على ${executions.length} execution\n`);
// 6. جلب credentials
console.log('6️⃣ جلب credentials...');
try {
const credentials = await n8n.getAllCredentials();
console.log(` ✅ تم العثور على ${credentials.length} credential\n`);
} catch (error) {
console.log(` ⚠️ ${error.message}\n`);
}
// 7. جلب إحصائيات
console.log('7️⃣ جلب إحصائيات n8n...');
const stats = await n8n.getStats();
console.log(` ✅ الإحصائيات:`);
console.log(` - إجمالي workflows: ${stats.totalWorkflows}`);
console.log(` - workflows نشطة: ${stats.activeWorkflows}`);
console.log(` - يوجد executions: ${stats.hasExecutions ? 'نعم' : 'لا'}\n`);
// 8. مثال على إنشاء workflow جديد (معلق - يمكن تفعيله)
/*
console.log('8️⃣ إنشاء workflow جديد...');
const newWorkflow = await n8n.createWorkflow({
name: 'Test Workflow from API',
nodes: [
{
parameters: {},
name: 'Start',
type: 'n8n-nodes-base.start',
typeVersion: 1,
position: [250, 300]
}
],
connections: {},
active: false
});
console.log(` ✅ تم إنشاء workflow: ${newWorkflow.name} (ID: ${newWorkflow.id})\n`);
*/
// 9. مثال على تنفيذ workflow (معلق - يمكن تفعيله)
/*
if (workflows.length > 0 && workflows[0].active) {
console.log(`9️⃣ تنفيذ workflow: ${workflows[0].name}...`);
const execution = await n8n.executeWorkflow(workflows[0].id, {
test: 'data'
});
console.log(` ✅ تم التنفيذ: ${execution.id}\n`);
}
*/
console.log('✅ اكتملت جميع الأمثلة بنجاح!');
} catch (error) {
console.error('❌ خطأ:', error.message);
process.exit(1);
}
}
// تشغيل الأمثلة
examples();