Build and Test Your APIs with Polygon.io Postman Collection
Jul 11, 2024
I've been building apps for a long time now; most of that time either with, or for, API-based developer platforms. The trick to being productive with APIs is always having some sort of test harness where you can experiment with calls, validate response payloads and ensure everything is working how you expect it prior to wiring up everything in your app or algorithm. One of the tools I have relied on for years to do this is Postman.
If you are not familiar with Postman, you can think of it as an IDE for working with APIs: you can design, build, test, mock endpoints, create workspaces for collaboration and different projects or environments, and much more. Signing up is free, and more than 30 million developers already use it for their projects. One of my favorite features is the public API network. Here, organizations can publish and share API collections for their services: if you want to use the Salesforce Platform APIs, there is a collection, send an SMS via Twilio, there is a collection too. You name it, you can probably find a collection.
Find hundreds of thousands of API collections in the Public API Network
As we continue to invest in optimizing the developer experience at Polygon and provide tools to help you be more productive, we published the official Polygon.io Postman collection. In this collection, you will find all of the public endpoints we support for Stocks, Indices, Options, Forex, and Crypto. At the time of writing, Postman doesn't allow you to create requests from public workspaces. To use the collection, you can either fork it into your own private workspace, or export the collection and import it via the desktop app.
Let's go ahead and download it locally by tapping the ... to the right of Polygon API and choose export (select version 2.1) . This will save a JSON file to your computer, which you can import via File > Import in the desktop app.
export collection to your desktop
Once imported, you need to add your Polygon.io API keys to the collection variables. If you don't have a Polygon.io account, you can sign up for free to get started. Once logged in, copy your API key from the dashboard.
Switch back to the Postman app, tap Polygon API (1), Variables (2) and paste the value into the apiKey variable (3), making sure you tap Save at the end. Now, your API key will be automatically added the correct authentication header for any API request.
Add your API Key to the Polygon.io Collection
Once you have your API Key variable set up, you can execute any of the endpoints your plan has access to. For example, let's get the previous close for AAPL. Navigate to the Previous Close endpoint (v2/aggs/ticker/{stockTicker}/prev).
Tapping on GET Previous Close brings up the API docs integrated into the overview tab. The great thing with Postman collections is that they can be generated via an openAPI spec, which Polygon.io conforms to. This ensures that documentation and endpoints are always current.
Looking at the docs, we can see that Previous Close requires a query param, adjusted, and variable, ticker to be set. Tap on the Params tab, enter the values below, then tap Send to see the results.
adjusted = false
stocksTicker = AAPL
JSON results displayed
Once you have your results, you can choose the format you prefer to see the payload in. I like the Pretty JSON option, but if you prefer raw, or plain text, it's as easy as selecting the option in Postman.
That's it. You can test and experiment with any of the other endpoints your plan has access to in the same way as demonstrated above. Postman collections are my goto tool if I want to get familiar with an API response prior to integrating it into my app. Very often, I will also save the payload to use in test stubs too.
We are excited to announce our integration with QuantConnect! This offering empowers users with state-of-the-art research, backtesting, parameter optimization, and live trading capabilities, all fueled by the robust market data APIs and WebSocket Streams of Polygon.io.
Polygon now includes daily historical Flat Files in all paid plans at no extra charge, featuring a new web-based File Browser and S3 access for simplified data exploration and integration.