Get Started with Polygon API
Let's look at the step-by-step instructions for getting an API key.
We'll cover the following
In order to use Polygon APIs, we first need to create an account on Polygon.io.
Create an account
Follow the steps below to create an account on Polygon successfully:
Go to the official Polygon page.
Click “Get your Free API Key.”
Enter your credentials in the given fields.
Click “Sign Up.”
A successful sign-up will take you to the dashboard of Polygon.
The slides given below demonstrate the process of creating an account on Polygon.
Get the API key
To retrieve the API key, follow the steps given below:
Log in to your Polygon account.
Scroll down until you see “API Keys.”
Copy the API key.
The slides below demonstrate the process of getting an API key.
Save the API key
Now that we have our API key, we can use it to access any endpoint available on Polygon.io. Let’s start by verifying our API key. To do this, we fetch news articles related to tickers using an endpoint available in Polygon.
Click the “Edit” button in the code widget below and enter the API you copied from Polygon. After that, click “Save” to replace the value of the API key throughout the course. Click “Run” to execute the code.
// Importing libraries hereimport fetch from "node-fetch";// Define API key hereconst apiKey = "{{API_KEY}}";// Define endpoint URL hereconst endpointUrl = new URL('https://api.polygon.io/v2/reference/news');// Define Header Parameters hereconst headerParameters = {authorization: `Bearer ${apiKey}`,contentType: 'application/json',};// Setting API call optionsconst options = {method: 'GET',headers: headerParameters,};// Function to make API callasync function fetchTickerNewsJSON() {try {const response = await fetch(endpointUrl, options);// Custom function for printing the API responseprintResponse(response);} catch (error) {// Custom function for printing the error messageprintError(error);}}// Calling function to make API callfetchTickerNewsJSON();
If the API key is valid, we’ll get a list of news articles related to different tickers. This endpoint will be discussed in detail later in the course.
Now that we have saved and verified our API key, let’s start learning about the different endpoints available in Polygon.