teamviewer.com link icon
or
Ask The Community

TeamViewer is one of the winners of the European Customer Centricity Award 🥳


Please find more information here.

Connect c# console to API

Hi

  I need to access devices list from a windows console to the TeamViewer API. So, it's not clear for me how to pass my secret and cliend id.  My actual code is

HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://webapi.teamviewer.com");

var url = "/api/v1/devices";
var resultat = await client.GetAsync(url);

For sure, this execution return to me a 401 code.  Do I need an authorization code?  If yes, how to obtain it dynamically without login user account or have a return url... To made it simple, how can I use my secret and client id to obtain access to this api?

Thanks,

Jean-David Rivard

Comments

  • DomLan
    DomLan Posts: 490 ⭐Star⭐

    Hi @support_ti,

    for your purpose I think it is preferable to use a "static" token, of the script type rather than having a combination of client code and secret. This is due to the fact that the second combination is useful for an authentication process via OAuth which necessarily requires a multi-step conversation between your console application and the TeamViewer servers, including opening browsers for entering credentials.

    In short:
    - if you register an App of App type, you get a client code and a secret to use via OAuth to acquire a TOKEN to use in your calls.
    - if you register an App of Script type, you alredy have the TOKEN to use in your calls.

    Once the token is obtained, the next step is to transmit it together with the call: you must use the HTTP call headers.

    HttpClient client = new HttpClient();
    client.BaseAddress = new Uri("https://webapi.teamviewer.com");
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "Your Oauth token");

    var url = "/api/v1/devices";
    var resultat = await client.GetAsync(url); 

     Regards

    Domenico Langone
    MCSD: App Builder
    Did my reply answer your question? Accept it as a solution to help others.
    Find this helpful? Say thanks by clicking on the Thumbs Up button.