Get Token using Excel xmlhttp

A place for developers to advertise their TheTVDB.com enabled app and get help from other developers with the API.
psychochimp
Posts: 1
Joined: Fri Jun 08, 2018 10:05 am

Get Token using Excel xmlhttp

Postby psychochimp » Fri Jun 08, 2018 10:24 am

Hi

I'm trying to obtain information from the api using Excel.

I've found some code that allows me to obtain, for example, episode information:

Code: Select all

    myurl = "https://api.thetvdb.com/series/80379/episodes/query?airedSeason=1"
    Token = "TOKENXYZ"
       
    xmlhttp.Open "GET", myurl, False
    xmlhttp.SetRequestHeader "Content-Type", "application/json"
    xmlhttp.SetRequestHeader "Authorization", "Bearer " & Token
    xmlhttp.Send


This corresponds to the CURL command:

Code: Select all

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer TOKENXYZ' 'https://api.thetvdb.com/series/80379/episodes/query?airedSeason=1'


But I'm not sure of the syntax of the xmlhttp command to do the login command:

Code: Select all

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{
  "apikey": "string",
  "userkey": "string",
  "username": "string"
}' 'https://api.thetvdb.com/login'


Can someone provide me with the Excel syntax to get the token?

Thanks

k_zeon
Posts: 16
Joined: Mon Nov 23, 2015 1:17 pm

Re: Get Token using Excel xmlhttp

Postby k_zeon » Mon Jun 11, 2018 1:41 pm

I use this in VB6

Code: Select all

 Dim JSON as string
    JSON = "{""apikey"":""<accountnum>"",""username"":""<username>"",""userkey"":""<Userkey>""}"
    Dim Result As String
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    URL = "https://api.thetvdb.com/login"
    objHTTP.Open "POST", URL, False
    objHTTP.setRequestHeader "Content-type", "application/json"
    objHTTP.send (JSON)
    Result = objHTTP.responseText


You then extract the token and store the token in Result. you then use the token to get show info
AuthCode = (token from Result) ' << just to show

Code: Select all

 Dim objHTTP As Object
    Dim Result As String
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    objHTTP.Open "GET", URL, False
    objHTTP.setRequestHeader "Authorization", "Bearer " & AuthCode
    objHTTP.setRequestHeader "Accept-Language", "en"
    objHTTP.send
    Result = objHTTP.responseText