Stock market data infrastructure
Request company profiles with JavaScript
Use server-side JavaScript fetch to load a company profile with a protected API key, timeout, and explicit exchange context.
Documentation revised
Keep the credential on the server
This Node.js example uses built-in fetch and AbortSignal.timeout. Run it in a server environment with STOCKMARKET_API_KEY configured. A browser bundle would expose the key to visitors, so a public application should call its own server endpoint instead.
const key = process.env.STOCKMARKET_API_KEY;
if (!key) throw new Error("Set STOCKMARKET_API_KEY");
const url = new URL("https://stockmarketapi.ai/api/v1/companies/AAPL");
url.searchParams.set("exchange", "NASDAQ");
const response = await fetch(url, {
headers: { "X-API-Key": key },
signal: AbortSignal.timeout(30000),
});
if (!response.ok) throw new Error(`API returned ${response.status}`);
const company = await response.json();
console.log({ ticker: company.ticker, exchange: company.exchange,
hasPrices: company.has_price_data,
latestFinancials: company.latest_financials_date });
Render nullable fields honestly
Check for null or absent profile values before displaying employees, website, or description. Do not turn an unknown headcount into zero. Use the returned ticker and exchange together when linking to other dataset requests.
Fetch dependent datasets conditionally
A profile response is not a complete company export. Check has_price_data and available reporting dates, then request prices or financials separately. If using profile_markdown_url, treat it as temporary and refresh the parent response when it expires.