Posted by ConceptImage
Henagon

Javascript API implementation for company access token

Hi,

I'm trying to use the Teamviewer API.


What's I'm planning to do:
Create de web page (in Wordpress administration) where all computers belong to a Teamviewer groups / user must display. I have to know if they are online or not.

Secondly, some actions are available on this page like update description device.

So I'm tring to implement it with javascript (jQuery actually but it's not a requirement).

Here is my code:

 

$.ajax({
// url /api/v1/users/<uID>/groups where I'm not sure about <uID> where can I found it ? url: "https://webapi.teamviewer.com/api/v1/users/XXXXXXX/groups", type: "GET", beforeSend: function(xhr) {
// appToken generated in my profil > application
var appToken = 'XXXXXXX-..........'; xhr.setRequestHeader("Authorization", 'Bearer ' + appToken)
},
error: function(xhr, status, error) { console.log(xhr); console.log(status); console.log(error);
}, success: function(data, textStatus, jqXHR) { console.log(data); console.log(textStatus); } });

 

I got a 404 error with this piece of code.
Can you help me, please ?
Thank

 

1 Reply
1 Accepted Solution

Accepted Solutions
Posted by DomLan
Heptagon
Solution

Re: Javascript API implementation for company access token

Hi @ConceptImage,

If you want to create a page that allows you to access the data of your license (corporate for example), in a transversal way, that is without starting from your specific user, you must create a script token and not application. Plese refer to API documentation 3.2 - Registering an application in the Management Console.

In your case I guess you need a script type token with Company authorization. Ref. 3.3

In this sense, users of your web page will not authenticate with their TeamViewer credentials to access your company's shared data, so they will be able to see all the devices in all the groups related to your license. Ref. 3.5 The authorization process -> When using private Script Tokens, there is no need for an authorization process. Access to the ac-count/company data through the TeamViewer API is defined when creating the token. The data that is ac-cessed is the account or company data of the user creating the token. Note that a Script Token is still valid after changing the user’s password.

The speech is completely different if you want each user in your license to access their portion of devices and groups that always belong to your company's license. In this case you will have to use OAuth and the process is very different, but you will need to manage the code on the pages also via PHP, due to the various prohibitions of calls CORS from the client. -> your actual 404 error!

Hope this help.

Regards.

Domenico Langone
MCSD: App Builder
1 Reply
Posted by DomLan
Heptagon
Solution

Re: Javascript API implementation for company access token

Hi @ConceptImage,

If you want to create a page that allows you to access the data of your license (corporate for example), in a transversal way, that is without starting from your specific user, you must create a script token and not application. Plese refer to API documentation 3.2 - Registering an application in the Management Console.

In your case I guess you need a script type token with Company authorization. Ref. 3.3

In this sense, users of your web page will not authenticate with their TeamViewer credentials to access your company's shared data, so they will be able to see all the devices in all the groups related to your license. Ref. 3.5 The authorization process -> When using private Script Tokens, there is no need for an authorization process. Access to the ac-count/company data through the TeamViewer API is defined when creating the token. The data that is ac-cessed is the account or company data of the user creating the token. Note that a Script Token is still valid after changing the user’s password.

The speech is completely different if you want each user in your license to access their portion of devices and groups that always belong to your company's license. In this case you will have to use OAuth and the process is very different, but you will need to manage the code on the pages also via PHP, due to the various prohibitions of calls CORS from the client. -> your actual 404 error!

Hope this help.

Regards.

Domenico Langone
MCSD: App Builder