I am trying to pull some stock data from Alpha Vantage in my DigitalOcean droplet (Ubuntu with Python pre-installed).

Below is the code snippet:

import requests
import json

r = requests.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&key=MYKEY')

print r.json()

I was expecting a JSON object like:

"Meta Data": {
        "1. Information": "Daily Time Series with Splits and Dividend Events",
        "2. Symbol": "IBM",
        "3. Last Refreshed": "2020-10-16",
        "4. Output Size": "Compact",
        "5. Time Zone": "US/Eastern"
    },
    "Time Series (Daily)": {
        "2020-10-16": {
            "1. open": "125.1700",
            "2. high": "126.4300",
            "3. low": "124.6550",
            "4. close": "125.9300",
            "5. adjusted close": "125.9300",
            "6. volume": "4714320",
            "7. dividend amount": "0.0000",
            "8. split coefficient": "1.0000"
        },
        "2020-10-15": {
            "1. open": "124.0800",
            "2. high": "125.2150",
            "3. low": "123.8500",
            "4. close": "124.8900",
            "5. adjusted close": "124.8900",
            "6. volume": "3389301",
            "7. dividend amount": "0.0000",
            "8. split coefficient": "1.0000"
        },
        "2020-10-14": {
            "1. open": "125.1300",
            "2. high": "126.9400",
            "3. low": "125.1300",
            "4. close": "125.9400",
            "5. adjusted close": "125.9400",
            "6. volume": "3730139",
            "7. dividend amount": "0.0000",
            "8. split coefficient": "1.0000"
        },

But I got:

{
    "Error Message": "the parameter apikey is invalid or missing. Please claim your free API key on (https://www.alphavantage.co/support/#api-key). It should take less than 20 seconds."
}

Having been debugging for hours… Could anyone help me out?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
3 answers

@bccoder I think the problem is misleading API Docs from AlphaVantage.co

You need to change the name of the parameter from: key to apikey.

So before:

r = requests.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&key=MYKEY')

after:

r = requests.get('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=MYKEY')

Seconding @AHA’s answer, the parameter is “apikey” instead of “key”. Below is a sample code snippet (source: Medium):

import requests
import json 

key = 'XXX'
ticker = 'IBM'
url = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol={}&apikey={}'.format(ticker, key)
response = requests.get(url)
print(response.json()) 

Best of luck!

Thanks to both answers, I have resolved the issue <3

Submit an Answer