All Collections
API Guide
How to
How to create a request
How to create a request

This article will guide you through the process of creating your first API request

Team avatar
Written by Team
Updated over a week ago

This article will help you understand how a URL request is organized and create it using several examples.

URL Basics

Each request is represented by a URL that consists of the following key components:

  • Base URL

  • Endpoint

  • Query String

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.

API credits

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.

Request example

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:

https://api.twelvedata.com/time_series?apikey=your_api_key&interval=1day&symbol=TSLA&outputsize=1

Base URL: https://api.twelvedata.com

Endpoint path: /time_series

Query string: 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.

https://api.twelvedata.com/time_series?symbol=AAPL,EUR/USD,ETH/BTC:Huobi,TRP:TSX&interval=1min&apikey=your_api_key

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.

https://api.twelvedata.com/dividends?symbol=AAPL&start_date=1970-01-01&apikey=your_api_key

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.

https://api.twelvedata.com/macd?symbol=MSFT&interval=1min&apikey=your_api_key 

Tip. Twelve Data has a request builder, which you can use to create a URL request.

Did this answer your question?