This article will help you understand how a URL request is organized and create it using several examples.
Each request is represented by a URL that consists of the following key components:
Base URL: Refers to the consistent part of our web address for API requests.
Endpoint: This part defines which data set you want to access. It could be time series, technical indicators, fundamentals, and much more.
Query string parameters: Query string parameters are how you can filter or sort the data returned from an API call. Certain query string parameters are required, while others are optional.
Each API endpoint also has a specific "weight," meaning how many API credits will be used if invoked. Weight for each endpoint can be consulted at the API documentation. To learn more about credits, visit this article.
You have an idea of how a URL request looks, so you can start building up your first API request.
For example, you need to pull out Tesla stock price for the previous day using the API documentation as a guide; you would structure your request like this:
apikey=your_api_key - unique API key,
&interval=1day - data at daily granularity,
&symbol=TSLA - symbol ticker of Tesla Inc.,
&outputsize=1 - only the last record
API credits: 1
Commonly used API requests
Below are a couple of practical API requests. Please note all of the following examples will consume your API credits, so please review this article before running requests.
1) Batch requests might be used on top of various endpoints and technical indicators. It extracts multiple datasets simultaneously.
2) Dividends request as part of the fundamentals dataset. The request below returns the amount of dividends paid out for the last 20+ years for Apple Inc.
3) MACD request. This example of MACD request returns current 30 values at a 1-minute interval for Microsoft Corporation. All technical parameters could be customized.
Tip. Twelve Data has a request builder, which you can use to create a URL request.