quran / quran.com-api

Quran.com content APIs
https://api-docs.quran.foundation/docs/category/content-apis
MIT License
930 stars 194 forks source link

Can't get tafsir from API #578

Closed eyadali05 closed 2 years ago

eyadali05 commented 2 years ago

Problem Description

Tried to use the API to get the tafsir of a specific verse in a surah, my status code keeps staying at 404, thus, no response

I can use other functions of the API just as fine, confirmed can get list of verses, list of chapters, list of verses in a chapter, chapter info..

What I tried

Tried to use my user agent, didn't work

My Code

# /usr/bin/python3
import requests
from rich import print

# Al-fatihah
chapter_id = 1
# 3rd verse (I confirmed the ID Number)
verse_id = 3

headers = {
        "User-Agent": "My Linux User Agent :)"
}

# URL as in documentation
url = "http://api.quran.com/api/v3/chapters/1/verses/3/tafsir"

response = requests.get(url, headers=headers)

print(f"Status code: {response.status_code}")
data = response.json()

if data:
  print(data)

output I get:

Status code: 404
Traceback (most recent call last):
  File "/home/eyadali/dev/quran-tafsir-api/data.py", line 17, in <module>
    data = response.json()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
naveed-ahmad commented 2 years ago

We changed the tafsir endpoint few months ago. Please use following endpoints:

Get list available tafsirs: https://api.qurancdn.com/api/v4/resources/tafsirs?language=en

Get tafsir for specific ayah: https://api.qurancdn.com/api/v4/tafsirs/ID_OR_SLUG/by_ayah/AYAH_KEY?locale=en&words=true

Sample api call: https://api.qurancdn.com/api/v4/tafsirs/tafseer-ibn-e-kaseer-urdu/by_ayah/1:1?locale=en&words=true

Tafsir is usually for group of ayahs, in this new api you'll get list of verses as well.

Also, please try to upgrade to v4, v3 is very old api. No plan to deprecate v3 but we will not push any fixes for v3. It's readonly now.

Also, join our discord server. We'll start posting API related change-log in #api channel