Get Financial Data with Financial Modeling Prep API

If you need to get real-time stock and financial data from various stock exchanges, Financial Modeling Prep (FMP) is an excellent choice. FMP is an API that lets you pull fundamental and technical financial data of more than 4,000 companies worldwide. In this blog post, we'll guide you through the process of accessing FMP's public API documentation and show how to use it with JavaScript.

Getting Started

To get started with the FMP API, you'll need to sign up for a free account and generate an API key. Once you have an account, you are ready to get the API docs.

Accessing the API Docs

You can access the FMP API docs here: https://financialmodelingprep.com/developer/docs. The API has a clear and detailed overview along with examples of how to use the API requests.

For instance, in the Company Valuation API section, the endpoint shows how to get price targets for a selected company. The URL is https://financialmodelingprep.com/api/v3/stock/price-target, and the required parameters are symbol and API key (apikey). The returned data is JSON, and you can set a limit for the results per page by adding a new parameter, called limit.

Example Code

To demonstrate the use of the FMP API, we will use JavaScript. Consider the following example where we will fetch the price targets of Apple Inc.

const apiKey = "yourapikey";
const symbol = "AAPL";

fetch(`https://financialmodelingprep.com/api/v3/stock/price-target/${symbol}?apikey=${apiKey}`)
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })
  .catch(err => console.log(err));

In the example above, we got the price targets by using the fetch function and applied the URL we got from the FMP API docs. We used the symbol "AAPL" for the company Apple Inc., which we set a constant above, and the API key from our account. The response will return the data array, which contains the price details.

Conclusion

Using the FMP API with JavaScript is pretty straightforward. The API documentation provided by FMP is clear and detailed with examples of how to use various API requests. We've walked through how to generate an API key, access the API docs, and use the fetch function to get price targets for a selected company, using JavaScript.

Related APIs