Issues with the API

A place for developers to advertise their TheTVDB.com enabled app and get help from other developers with the API.
dlflannery
Posts: 35
Joined: Sat Oct 16, 2010 8:27 am
Location: Southwest Ohio, USA

Thu Nov 14, 2019 7:04 pm

1AE
User avatar
szsori
Site Admin
Posts: 2270
Joined: Fri Nov 03, 2006 2:23 pm

Thu Nov 14, 2019 7:23 pm

I tried your API key out on the Swagger page (https://api.thetvdb.com/swagger). For the auth string I was able to use the following:

Code: Select all

{
  "apikey": "....1AE",
  "username": "my-username-here",
  "userkey": "my-userkey-here"
}
I also tried it without the username and userkey. Both tests worked and I was able to get a token. Are you able to try out the Swagger page to make sure it works with your information? If you're passing a username and userkey to it (shouldn't be necessary), then make sure the userkey you're using matches what is shown here:
https://www.thetvdb.com/dashboard/account/editinfo

If you've hard-coded your username and userkey into your source, send me a PM with both and I'll update your userkey in the system to match.
dlflannery
Posts: 35
Joined: Sat Oct 16, 2010 8:27 am
Location: Southwest Ohio, USA

Thu Nov 14, 2019 8:30 pm

My code doesn't use my credentials, just the API key. Swagger was successful getting token with my API keyl.

Here is the snippet of my C# code that gets the token:

string jsonStr = "{\"apikey\": \"" + apiKey + "\"}";
UTF8Encoding encoding = new UTF8Encoding();
byte[] byte1 = encoding.GetBytes(jsonStr);

try
{
HttpWebRequest wreq = (HttpWebRequest)WebRequest.Create("https://api.thetvdb.com/login");
wreq.ContentType = "application/json; charset=utf-8";
wreq.Method = "POST";
wreq.ContentLength = byte1.Length;
Stream newStream = wreq.GetRequestStream();
newStream.Write(byte1, 0, byte1.Length);
newStream.Close();

// Get the response.
WebResponse response = wreq.GetResponse();
var streamReader = new StreamReader(response.GetResponseStream());
string result = streamReader.ReadToEnd();
Dictionary<string, string> tokenDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(result);
newToken = tokenDict["token"];
ClassSettings.tvdbRestApiKey = newToken;
}

Sorry but the forum won't let me go to "Full Editor & Preview", so I
can't put the code in a code block.

This is what has been working up til now.
dlflannery
Posts: 35
Joined: Sat Oct 16, 2010 8:27 am
Location: Southwest Ohio, USA

Thu Nov 14, 2019 8:37 pm

(I tried to edit this into the previous post. Forum won't let me)

The getRequestStream errors out with the message:
"The underlying connection was closed. An unexpected error occurred on a send:
User avatar
szsori
Site Admin
Posts: 2270
Joined: Fri Nov 03, 2006 2:23 pm

Thu Nov 14, 2019 8:44 pm

Can you ping api.thetvdb.com and let me know what it resolves to for you?
User avatar
szsori
Site Admin
Posts: 2270
Joined: Fri Nov 03, 2006 2:23 pm

Thu Nov 14, 2019 8:45 pm

For reference:
Pinging d28ljkmapxhl0h.cloudfront.net [13.226.15.58] with 32 bytes of data:
dlflannery
Posts: 35
Joined: Sat Oct 16, 2010 8:27 am
Location: Southwest Ohio, USA

Thu Nov 14, 2019 8:50 pm

Correction: It's wreq.GetResponse() that errors out.
dlflannery
Posts: 35
Joined: Sat Oct 16, 2010 8:27 am
Location: Southwest Ohio, USA

Thu Nov 14, 2019 8:52 pm

C:\Users\Dave>ping api.thetvdb.com

Pinging d28ljkmapxhl0h.cloudfront.net [13.225.224.83] with 32 bytes of data:
User avatar
szsori
Site Admin
Posts: 2270
Joined: Fri Nov 03, 2006 2:23 pm

Thu Nov 14, 2019 9:28 pm

You're seeing a different IP because you're in a different region, even though we're geographically close. No issues there.

I tested with curl and it's still working for me:

Code: Select all

curl -X POST https://api.thetvdb.com/login   -H 'Content-Type: application/json; charset=utf-8'   -d '{"apikey":"YOURAPIKEY"}' -H 'Host: api.thetvdb.com'
I'm kind of at a loss, but you should try curl to confirm you're getting a token that way as well.
dlflannery
Posts: 35
Joined: Sat Oct 16, 2010 8:27 am
Location: Southwest Ohio, USA

Thu Nov 14, 2019 10:53 pm

I'm trying curl with no success so far. If I copy the curl command code you posted into a Win10 command window, substituting my API key, I get this response:

{"Error":"Bad Content-Type or charset, expected 'application/json'"}curl: (6) Could not resolve host: application
curl: (6) Could not resolve host: charset=utf-8'
curl: (6) Could not resolve host: api.thetvdb.com'
Post Reply