Skip to main content
All CollectionsAPI GuideHow 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 explains the structure of a URL request and guides you through creating one with detailed examples.

URL Basics

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

  • Base URL

  • Endpoint

  • Query String

The Base URL refers to the fixed part of the web address used for API requests. The Endpoint specifies the dataset you want to access, such as time series, technical indicators, fundamentals, and more. Query String Parameters are used to filter or sort the data returned by an API call; some parameters are mandatory, while others are optional.

API credits

Each API endpoint has a specific "weight," indicating the number of API credits consumed per request. You can find the weight for each endpoint in the API documentation. For more details about credits, refer to this article.

Request example

Now that you understand the structure of a URL request, you’re ready to build your first API request.

For instance, if you want to retrieve Tesla's stock price for the previous day, using the API documentation as a reference, your request would look 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 Parameters:

    • apikey=your_api_key — Your unique API key

    • &interval=1day — Data at daily granularity

    • &symbol=TSLA — Tesla Inc. ticker symbol

    • &outputsize=1 — Retrieves only the most recent record

  • API Credits Used: 1

Commonly used API requests

Below are two practical examples of API requests. Please note that executing these examples will consume your API credits. To avoid unexpected charges, we recommend reviewing this article carefully before running the requests.

1) Batch requests can be utilized across various endpoints and technical indicators, allowing the simultaneous extraction of multiple datasets.

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 demonstrates a MACD request, returning the most recent 30 values at 1-minute intervals for Microsoft Corporation. All technical parameters are fully customizable.

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

Tip: Twelve Data offers a request builder tool that allows you to easily generate a customized URL request.

Did this answer your question?