-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample1.js
More file actions
49 lines (40 loc) · 1.46 KB
/
example1.js
File metadata and controls
49 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Configuration, AccessTokensApi, LinksApi, StatisticsApi, WorkspacesApi } from "urlr-js"
const username = process.env.URLR_API_USERNAME; // to be defined on your side
const password = process.env.URLR_API_PASSWORD; // to be defined on your side
// Access Tokens
let configuration = new Configuration();
const accessTokensApi = new AccessTokensApi(configuration);
accessTokensApi.createAccessToken({
createAccessTokenRequest: {
username: username,
password: password,
}
}).then(function (data) {
configuration = new Configuration({
accessToken: data.token,
basePath: baseUrl
});
// Workspaces - get workspace id
const workspacesApi = new WorkspacesApi(configuration);
workspacesApi.getTeams().then(function (workspaces) {
const workspaceId = workspaces.teams[0].id;
// Create a link
const linksApi = new LinksApi(configuration);
linksApi.createLink({
createLinkRequest: {
url: 'https://github.com/URLR',
teamId: workspaceId,
}
}).then(function (link) {
// Get statistics
const statisticsApi = new StatisticsApi(configuration);
statisticsApi.getStatistics({
getStatisticsRequest: {
linkId: link.id,
}
}).then(function (statistics) {
console.log(statistics);
}).catch((error) => console.error(error));
}).catch((error) => console.error(error));
}).catch((error) => console.error(error));
}).catch((error) => console.error(error));