-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
64 lines (57 loc) · 1.9 KB
/
Copy pathmain.js
File metadata and controls
64 lines (57 loc) · 1.9 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
// main.js
const { Actor } = require("apify");
const { default: axios } = require("axios");
Actor.main(async () => {
try {
// 1. Get input from Apify task / API
const input = (await Actor.getInput()) || {};
console.log("Received input:", input);
const allowedFields = [
"includeKeyword",
"locationName",
"countryName",
"pagesToFetch",
"companyName",
"jobType",
"datePosted",
"targetLocations",
];
const unsupported = Object.keys(input).filter(
(key) => !allowedFields.includes(key)
);
if (unsupported.length > 0) {
throw new Error(
`Unsupported parameter${unsupported.length > 1 ? "s" : ""}: ` +
`${unsupported.join(", ")}. This Actor only supports: ` +
`${allowedFields.join(", ")}.`
);
}
const missingFields = ["includeKeyword", "locationName", "countryName"].filter(
(field) => !input[field]
);
if (missingFields.length > 0) {
throw new Error(
`Missing required input field(s): ${missingFields.join(", ")}. This Actor ` +
"expects includeKeyword, locationName, countryName, pagesToFetch " +
"(optional: companyName, jobType, datePosted) -- check your input " +
"against the Actor's input schema."
);
}
const { userIsPaying } = Actor.getEnv();
const isFreeUser = !userIsPaying;
// 2. Call your external API
const res = await axios.post("https://api.orgupdate.com/search-jobs-v1", {
...input,
isFreeUser,
source: "reed",
});
const jobs = res.data;
// 3. Store results into Apify dataset
await Actor.pushData(jobs);
console.log(`✅ Saved ${jobs.length || 0} jobs to dataset`);
// Actor ends automatically when main() resolves
} catch (err) {
console.error("❌ Job search failed:", err.message);
throw err; // Actor will be marked as FAILED in console
}
});