mediathekview / mediathekviewweb

Eine Weboberfläche als Alternative zum Java-Client
https://mediathekviewweb.de/
GNU General Public License v3.0
898 stars 67 forks source link

API gives "Bad Request" #230

Closed moridius closed 2 years ago

moridius commented 2 years ago

I'm trying to use the API but I always get error 400, Bad Request.

I read this gist and tried to do the same in Python:

#!/usr/bin/env python3

import urllib.request

query = {
    "queries": [
        {
            "fields": ["title", "topic"],
            "query": "sturm der liebe"
        }
    ],
    "sortBy": "timestamp",
    "sortOrder": "desc",
    "future": False,
    "offset": 0,
    "size": 10,
    "duration_min": 20,
    "duration_max": 100
}

data = urllib.parse.urlencode(query).encode("utf-8")
with urllib.request.urlopen("https://mediathekviewweb.de/api/query", data) as f:
    print(f.read().decode("utf-8"))

Did the API change or am I missing something here?

bagbag commented 2 years ago

You're probably missing Content-Type: text/plain. Yes, it's wrong and stupid, but it is what it is right now.

moridius commented 2 years ago

That was actually part of the problem (and also my JSON was wrong...). Thanks!