Posted by monkeyman
Electron

Javascript API implementation

I've been playing with the api today (working well through postman) but when i try to access with javascript i'm getting "Response for preflight has invalid HTTP status code 405".

I understand that this is due to adding the additional request headers for the Authorization etc but i dont know how to resolve.. do you have any guides or tips on how to get around this?

var xhr = new XMLHttpRequest(),
    method = "GET",
    url = "https://webapi.teamviewer.com/api/v1/sessions";

xhr.open(method, url, true);
xhr.setRequestHeader('Authorization', '2793660-XXXXXXXXXXXXX');
xhr.onreadystatechange = function () {
  if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
    console.log(xhr.responseText);
  }
};
xhr.send();

 

 

1 Reply
Posted by DomLan
Heptagon

Re: Javascript API implementation

Hi @monkeyman,

you can find all documentation in TeamViewer API doc

In my opinion it is necessary to indicate which type of token belongs to the code reported in the Authorization header (Although it seems strange to me that the error returned is 405): 

xhr.setRequestHeader('Authorization', 'Bearer 2793660-XXXXXXXXXXXXX');

In any case, do you want to read sessions using a token derived from a domain authorization code or one acquired via OAuth for the connected operator? 

Regards

Domenico Langone
MCSD: App Builder