First start n8n seed & activate
Run Tests on Branches / Detect Changes (push) Successful in 14s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Parapharmacy API Tests (push) Successful in 1m35s
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
Run Tests on Branches / Detect Changes (push) Successful in 14s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Parapharmacy API Tests (push) Successful in 1m35s
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
// Activate all inactive n8n workflows via API.
|
||||
// Usage: node activate-workflows.js <email> <password>
|
||||
import http from 'node:http';
|
||||
|
||||
const [, , email, password] = process.argv;
|
||||
if (!email || !password) {
|
||||
console.error('Usage: node activate-workflows.js <email> <password>');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const HOST = 'n8n';
|
||||
const PORT = 5678;
|
||||
|
||||
function request(method, path, body, cookie) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const opts = {
|
||||
hostname: HOST, port: PORT, path, method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
};
|
||||
if (cookie) opts.headers['Cookie'] = cookie;
|
||||
|
||||
const req = http.request(opts, (res) => {
|
||||
const chunks = [];
|
||||
res.on('data', (c) => chunks.push(c));
|
||||
res.on('end', () => {
|
||||
const raw = Buffer.concat(chunks).toString();
|
||||
const setCookie = res.headers['set-cookie'];
|
||||
let cookieVal = cookie;
|
||||
if (setCookie) {
|
||||
const match = setCookie.find((c) => c.startsWith('n8n-auth='));
|
||||
if (match) cookieVal = match.split(';')[0];
|
||||
}
|
||||
let data;
|
||||
try { data = JSON.parse(raw); } catch { data = raw; }
|
||||
resolve({ status: res.statusCode, data, cookie: cookieVal });
|
||||
});
|
||||
});
|
||||
req.on('error', reject);
|
||||
if (body) req.write(JSON.stringify(body));
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// 1. Login
|
||||
console.log('[activate] Logging in...');
|
||||
const login = await request('POST', '/api/v1/login', { email, password });
|
||||
if (!login.cookie) {
|
||||
console.error('[activate] Login failed — no session cookie.');
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('[activate] Login OK.');
|
||||
|
||||
// 2. List workflows
|
||||
const list = await request('GET', '/api/v1/workflows', null, login.cookie);
|
||||
const workflows = list.data?.data || list.data || [];
|
||||
if (!Array.isArray(workflows)) {
|
||||
console.error('[activate] Unexpected response:', JSON.stringify(list.data).slice(0, 200));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// 3. Activate inactive ones
|
||||
let activated = 0;
|
||||
for (const wf of workflows) {
|
||||
if (!wf.active) {
|
||||
const res = await request('PATCH', `/api/v1/workflows/${wf.id}`, { active: true }, login.cookie);
|
||||
if (res.status < 300) {
|
||||
console.log(`[activate] Activated: ${wf.name || wf.id}`);
|
||||
activated++;
|
||||
} else {
|
||||
console.error(`[activate] Failed to activate ${wf.id}: HTTP ${res.status}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[activate] Done. ${activated} workflow(s) activated.`);
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error('[activate] Error:', err.message);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user