-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5.listTasks.js
More file actions
133 lines (116 loc) · 4.35 KB
/
5.listTasks.js
File metadata and controls
133 lines (116 loc) · 4.35 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* Description:
* Return a paginated list of all workflow tasks, sorted by creation time.
* Each task includes basic information such as status and creation time.
*
* Documentation:
* https://www.browseract.com/reception/integrations/api-workflow
*
* curl -X GET 'https://api.browseract.com/v2/workflow/list-tasks?workflow_id=&page=1&limit=10' -H 'Authorization: Bearer app-abcdefghijklmn'
*/
const https = require('https');
function main() {
// API Key Required for API Call, generated from: https://www.browseract.com/reception/integrations
const authorization = "app-abcdefghijklmn";
// Specify the workflow ID to filter tasks.
// When provided, return only tasks associated with the specified workflow.
// If omitted, return tasks from all workflows.
// You can copy it from: https://www.browseract.com/reception/workflow-list
const workflowId = "";
// Page number (minimum: 1, default: 1)
const page = 1;
// Number of items per page (minimum: 1, maximum: 500, default: 1)
const limit = 10;
try {
const options = {
hostname: 'api.browseract.com',
port: 443,
path: `/v2/workflow/list-tasks?workflow_id=${workflowId}&page=${page}&limit=${limit}`,
method: 'GET',
headers: {
'Authorization': `Bearer ${authorization}`
}
};
const req = https.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
if (res.statusCode === 200) {
// success example:
// {'page': 1, 'limit': 10, 'items': [], 'total_pages': 0, 'total_count': 0}
// success example with data: Please refer to the bottom of this file
console.log('api-call-ok:', responseData);
const response = JSON.parse(responseData);
const totalCount = response.total_count;
const currentPage = response.page;
const currentLimit = response.limit;
const items = response.items;
const currentItems = items.length;
console.log(`Total records: ${totalCount}, Current page records: ${currentItems}`);
console.log(`Page: ${currentPage}, Limit: ${currentLimit}`);
// Display task items
if (currentItems > 0) {
console.log('\nTask List:');
items.forEach(item => {
console.log('ID:', item.id);
console.log('Status:', item.status);
console.log('Workflow ID:', item.workflow_id);
console.log('---');
});
}
} else {
// error example:
// {"code": 401, "msg": "Invalid authorization", "data": null, "ts": 1759917250113, "time": "2025-10-08 09:54:10", "traceId": "bcdef"}
console.log(`api-call-error: status=${res.statusCode}`, responseData);
}
});
});
req.on('error', (error) => {
console.log('run-error:', error.message);
});
req.end();
} catch (error) {
console.log('run-error:', error.message);
}
}
main();
/*
success example:
{
"page": 1,
"limit": 10,
"items": [{
"id": "16628193563511975",
"workflow_id": "16217357109956214",
"input_parameters": [
{
"name": "target_url",
"value": "https://www.google.com/search?q=iphone17"
},
{
"name": "product_limit",
"value": "10"
}
],
"output": {
"string": null,
"files": null
},
"status": "created",
"live_url_info": {
"width": 1280,
"height": 1024,
"live_url": "https://www.browseract.com/remote/abcde"
},
"live_url": "https://www.browseract.com/remote/abcde",
"profile_id": "abcdef",
"created_at": null,
"finished_at": null,
"task_failure_info": null
}],
"total_pages": 1,
"total_count": 1
}
*/