Search code examples
c#winformsteamviewer

Using the TeamViewer API


I am looking to create a C# application that will report on the connections that we make to customers. I am looking into the TeamViewer API, but I cannot get the code below to authenticate:

string accessToken = "xxxxxxxxxxxxxxxxxxx";
string apiVersion = "v1";
string tvApiBaseUrl = "https://webapi.teamviewer.com";
string address = tvApiBaseUrl + "/api/" + apiVersion + "/reports/connections";

try
{
    // Create the web request  
    HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
    request.Headers.Add("Bearer", accessToken);
    request.Method = "GET";
    WebResponse webResp = request.GetResponse();
}
catch (Exception)
{
    // Do nothing for now
}

Solution

  • Use fiddler and make sure your requests include the authorization header.

    All API requests need to include the "Authorization" header if the API function requires an access token.

    Example

    GET /api/v1/users HTTP/1.1 
    Host: webapi.teamviewer.com 
    Authorization: Bearer 54213-2YotnFZFEjr1zCsicMWp 
    

    Also examine what they are sending you back, it may provide a clue.

    UPDATE

    Try this change

    request.Headers.Add("Authorization", "Bearer " + accessToken);