/
get-StoryousDataOfMarketPlaceBillsByAPI.pq
107 lines (107 loc) · 4.45 KB
/
get-StoryousDataOfMarketPlaceBillsByAPI.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 =
(token as text, Id as text) =>
let
header = [
#"Authorization" = token
],
call =
Json.Document(
Web.Contents(
"https://api.storyous.com/merchants",
[
RelativePath = Id,
Headers = header
]
)
),
tbl = Record.ToTable(call),
trnsp =
Table.ExpandListColumn(
Table.PromoteHeaders(
Table.Transpose(tbl),
[PromoteAllScalars = true]
),
"places"
),
placeCodes = Record.FieldNames(trnsp[places]{0}),
expandPlaces =
Table.ExpandRecordColumn(
trnsp,
"places",
placeCodes,
List.Transform(
placeCodes,
each _ & ".places"
)
),
getBills =
Table.AddColumn(
expandPlaces,
"bills",
each
let
getBill =
List.Generate(
() =>
[
URL = [merchantId] & "-" & [placeId.places],
Result =
Json.Document(
Web.Contents(
"https://api.storyous.com/bills",
[
RelativePath = URL,
Headers = header
]
)
)
],
each [URL] <> null,
each
[
URL = [Result][nextPage],
Result =
Json.Document(
Web.Contents(
"https://api.storyous.com",
[
RelativePath = URL,
Headers = header
]
)
)
]
)
in
getBill
),
expandBills =
Table.ExpandListColumn(
getBills,
"bills"
)
in
expandBills,
documentation = [
Documentation.Name = " get-StoryousDataOfMarketPlaceBillsByAPI.pq ",
Documentation.Description = " Getting data from Storyous about Markets, Places and their bills by API. Need Previous funcions get-StoryousAPIKey.pq ",
Documentation.Source = "https://www.jaknapowerbi.cz",
Documentation.Version = " 1.0 ",
Documentation.Author = " Štěpán Rešl ",
Documentation.Examples = {
[
Description = " Input: #""Token"", marketID ",
Code = "",
Result = ""
]
}
]
in
Value.ReplaceType(
output,
Value.ReplaceMetadata(
Value.Type(output),
documentation
)
)