TypeScript / JavaScript
Submit and poll from a server-side JavaScript application.
const baseUrl = "https://api.runharvester.com/api/v1/data";
const apiKey = process.env.RUNHARVESTER_API_KEY;
if (!apiKey) throw new Error("RUNHARVESTER_API_KEY is required");
const response = await fetch(`${baseUrl}/requests`, {
method: "POST",
headers: {
"X-API-Key": apiKey,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({ url: "https://example.com", mode: "auto", proxy: "random" }),
});
if (!response.ok) throw new Error(`Submit failed: ${response.status}`);
const request = await response.json();
const result = await fetch(`${baseUrl}/requests/${request.id}/result`, {
headers: { "X-API-Key": apiKey },
});Keep this code on a trusted server. A browser client would expose the API key.
Last updated on