-
Notifications
You must be signed in to change notification settings - Fork 13
/
get-ActivityEventsForPeriod.pq
107 lines (107 loc) · 5.16 KB
/
get-ActivityEventsForPeriod.pq
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
let
output =
(generatedToken as text, startDate as date, endDate) =>
let
listofDates =
List.Dates(
startDate,
Number.From(endDate - startDate),
#duration(1, 0, 0, 0)
),
transformator =
List.Transform(
listofDates,
each
let
startDateTimeVariable =
"'"
& Date.ToText(
_,
"yyyy-MM-ddT00:00:00.000Z"
)
& "'",
endDateTimeVariable =
"'"
& Date.ToText(
_,
"yyyy-MM-ddT23:59:59.999Z"
)
& "'",
apiCall =
Json.Document(
Web.Contents(
"https://api.powerbi.com/v1.0/myorg",
[
RelativePath = "admin/activityevents",
Headers = [
#"Content-Type" = "application/json",
Authorization = generatedToken
],
Query = [
startDateTime = startDateTimeVariable,
endDateTime = endDateTimeVariable
]
]
)
),
generator =
List.Buffer(
List.Generate(
() =>
[
result = apiCall,
uri = result[continuationUri]?,
lastResultSet = result[lastResultSet]?
],
each [uri] <> null,
each
[
result =
Json.Document(
Web.Contents(
uri,
[
Headers = [
#"Content-Type" = "application/json",
Authorization = generatedToken
]
]
)
),
uri = _[result][continuationUri]?,
lastResultSet = _[result][lastResultSet]?
],
each [result][activityEventEntities]?
)
),
convertor = List.RemoveNulls(List.Combine(generator))
in
convertor
),
listOutputConvertor = List.RemoveNulls(List.Combine(transformator))
in
#table(
type table [content = record],
List.Transform(
listOutputConvertor,
each
{
_
}
)
),
documentation = [
Documentation.Name = " get-ActivityEvents.pq ",
Documentation.Description = " Get All activity events from selected date ",
Documentation.Source = "https://www.jaknapowerbi.cz",
Documentation.Version = " 1.0 ",
Documentation.Author = " Štěpán Rešl "
]
in
Value.ReplaceType(
output,
Value.ReplaceMetadata(
Value.Type(output),
documentation
)
)