API V2.x Discussion

A place for developers to advertise their TheTVDB.com enabled app and get help from other developers with the API.
devildant
Posts: 58
Joined: Sun Dec 21, 2014 5:13 pm

Re: API V2.x Discussion

Postby devildant » Mon Aug 22, 2016 9:02 am

rudras wrote:i have wriiten a httpreq code to get tokens
however i always receives not authorized

var options = {
host:'api.thetvdb.com',
path:'/login',
method: 'POST',
json:true,
headers: {'Content-Type': 'application/json',Accept: 'application/json'},
body: {apikey:"**", username: "***", userkey:"***" }
};

var req = https.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);

//res1.writeHead(200, {'Content-Type': 'application/json'});
res1.end('Hello World NodeJS \n'+chunk);
});
});

any idea , why its returns not authorized.


it's work when you try directly from https://api.thetvdb.com/swagger ?

rudras
Posts: 3
Joined: Sat Aug 20, 2016 11:19 pm

Re: API V2.x Discussion

Postby rudras » Mon Aug 22, 2016 10:05 am

Yes , its working correctly from https://api.thetvdb.com/swagger and using curl from command line.

tehjrow
Posts: 4
Joined: Wed Feb 17, 2016 9:23 am

Re: API V2.x Discussion

Postby tehjrow » Mon Aug 22, 2016 11:15 am

rudras wrote:i have wriiten a httpreq code to get tokens
however i always receives not authorized

var options = {
host:'api.thetvdb.com',
path:'/login',
method: 'POST',
json:true,
headers: {'Content-Type': 'application/json',Accept: 'application/json'},
body: {apikey:"**", username: "***", userkey:"***" }
};

var req = https.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);

//res1.writeHead(200, {'Content-Type': 'application/json'});
res1.end('Hello World NodeJS \n'+chunk);
});
});

any idea , why its returns not authorized.


I don't know enough about node to troubleshoot, but this is how I do it in C#.

Code: Select all

//Sets the token from the apikey from tvdb
        private async Task SetToken(string ApiKey)
        {


            using (HttpClient client = new HttpClient())
            {
                //Url to TVDB
                Uri url = new Uri("https://api.thetvdb.com/login");

                //Set Accept request header
                client.DefaultRequestHeaders
                      .Add("Accept", "application/json");

                //Setup request message with json apikey and content-type header
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
                request.Content = new StringContent("{\"apiKey\":\"" + ApiKey + "\"}",
                                                    Encoding.UTF8,
                                                    "application/json");

                //Send via post, get response, read content into string, check to be sure it was OK
                HttpResponseMessage resp = await client.SendAsync(request);
                string respString = await resp.Content.ReadAsStringAsync();
                if(resp.ReasonPhrase != "OK")
                {
                    throw new Exception(resp.ReasonPhrase);
                }

                //Read into byte array and them create a memory stream
                byte[] byteArray = Encoding.UTF8.GetBytes(respString);
                MemoryStream stream1 = new MemoryStream(byteArray);

                //Create serializer and read the stream into a Token object
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Token));
                _token = serializer.ReadObject(stream1) as Token;

                //Set global token for debugging
                tokenString = _token.token;
            }
        }
       

devildant
Posts: 58
Joined: Sun Dec 21, 2014 5:13 pm

Re: API V2.x Discussion

Postby devildant » Mon Aug 22, 2016 2:26 pm

rudras wrote:Yes , its working correctly from https://api.thetvdb.com/swagger and using curl from command line.

try this : body: '{"apikey":"**", "username': "***", "userkey":"***" }'

WilliamABradley
Posts: 3
Joined: Mon Mar 24, 2014 3:49 am

Re: API V2.x Discussion

Postby WilliamABradley » Tue Aug 23, 2016 4:15 am

Just like there is a Series/Filter Endpoint, could we get an Episode and Episode/Filter Endpoint? Since Episode IDs are Unique for every single episode in the Database, it would be great if we could run a filter via the Episode ID, that way we can check the last Updated status of an Episode Directly, and update it via that means, rather than downloading and building a whole Series Object. It is pretty quick, but I'm thinking about data saving.

The way my app works, is that it pulls all of the Series Data into an SQLite Database, including episodes and everything, but only the Shows that the user of my app follows. It would be great for me to be able to iterate via all of the Episodes (or via the Series object if it has been updated), and then if Last Updated has changed, update that database Entity. It would save processing power if it didn't have to load unnecessary information at the same time.
Thanks,
William

WilliamABradley
Posts: 3
Joined: Mon Mar 24, 2014 3:49 am

Re: API V2.x Discussion

Postby WilliamABradley » Tue Aug 23, 2016 7:30 am

Also just discovered that filtering a Series properties with LastUpdated, and any other properties, LastUpdated doesn't appear in results.

rudras
Posts: 3
Joined: Sat Aug 20, 2016 11:19 pm

Re: API V2.x Discussion

Postby rudras » Tue Aug 30, 2016 10:39 pm

How to do an exact match on series name .
my intension is to search series name "LOST"

when i am using https://api.thetvdb.com/search/series?name=LOST , it retuns a 30 series in which "lost" is there a part of the series name .'
Is there anyway we can do a exact match of string.

imniklas
Posts: 2
Joined: Fri Sep 02, 2016 2:18 am

Re: API V2.x Discussion

Postby imniklas » Fri Sep 02, 2016 2:21 am

Why isn't there a UNIX timestamp for when each episode aired? How can I know what time each episode airs?

random_dev
Posts: 4
Joined: Tue Sep 06, 2016 5:27 pm

Re: API V2.x Discussion

Postby random_dev » Tue Sep 06, 2016 6:05 pm

Is there any way to get the episodes of a show in order? i.e. when querying /series/{id}/episodes I seem to get episodes in a random order. It would be really great if I could get that in air-date order.

Does anyone know if that's possible?

Thanks

imniklas
Posts: 2
Joined: Fri Sep 02, 2016 2:18 am

Re: API V2.x Discussion

Postby imniklas » Thu Sep 08, 2016 3:30 am

random_dev wrote:Is there any way to get the episodes of a show in order? i.e. when querying /series/{id}/episodes I seem to get episodes in a random order. It would be really great if I could get that in air-date order.

Does anyone know if that's possible?

Thanks

I don't believe so, you have to sort them by yourself. What I do is I put them within a season object for every season, and put them in the right one and on the right spot based on the airedSeason and airedEpisodeNumber properties.

On an unrelated note, does anyone know if it's possible to get the air time of an episode? From what I can see, the only way to do this is by checking it as a property of the show, but that does not work very good since different episodes can air at different times during a show's lifecycle. It also does not give me any information about the timezone which will make it impossible to create a countdown to an episode. Any advice is appriciated! Thanks in advanced :)