Forum Discussion
Issue with ‘Scheduled Refresh’ for api calls
- Anonymous5 years ago
Hi Anonymous,
It seems like the power query not allow you direct do merge operations between different types(number and text), please try to use the following code of 'add custom column' step, I added text type convert in the formula.
#"Added Custom" = Table.AddColumn(#"Converted to Table1", "Source", each Json.Document(Web.Contents("https://api.xyz.com/", [ Headers=[#"Gen-Api-Key"="...."], RelativePath="natgas/events/v1/notices/details", Query= [ ids=Text.From([Column1]), format="json" ] ])))Regards,
Xiaoxin Sheng
- Anonymous5 years ago
Hi Anonymous and all: Good day! I found checking the data in the data base table and Api portal that for some pipes there will be same event posted for different locations [as they are impacted for all those locations for a pipeline]. That's why the multiple location rows are coming for those pipes! So, it's actually not an error/issue, but a fact! So, I am closing this thread. Thanks all for your patience. 🙂
Hi Anonymous and all:Thanks a lot for your response. I tried to follow the steps you mentioned. I am not sure what to do at the last step you mentioned:
Add a new column to the current table and use the connector function to invoke data based on current id: (use id column name as a parameter in the connector)
#"Added Custom" = Table.AddColumn(#"Converted to Table", "Source", each Json.Document(Web.Contents("https://api.xyz.com/natgas/events/v1/notices/details?ids=" & [NoticeId] & "&format=json", [Headers=[#"Gen-Api-Key"="……"]])))
I selected ‘Add Column’-> ‘Custom Column’-> then copy-pasted the code in ‘notice_detail’ function in the ‘Custom column formula’.
After that I get a new Column, ‘Custom’ with ‘Function’ in each cell for different ids in the table. Not sure what to do now?
The code from advanced editor [in blue is similar to your code]
-----------------------------------
let
Source = Json.Document(Web.Contents("https://api.xyz.com/",
[
RelativePath="natgas/events/v1/notices",
Query=
[
priorities="critical",
limit="50",
offset="0",
format="json"
]
,
Headers=[
#"Gen-Api-Key"="......."
]
]
)),
data = Source[data],
#"Converted to Table" = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "pipelineName", "priority", "type", "subject", "postDate", "effDate", "endDate"}, {"id", "pipelineName", "priority", "type", "subject", "postDate", "effDate", "endDate"}),
id1 = #"Expanded Column1"[id],
#"Converted to Table1" = Table.FromList(id1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Custom" = Table.AddColumn(#"Converted to Table1", "Custom", each (NoticeId as number) => let
Source = Json.Document(Web.Contents("https://api.xyz.com/natgas/events/v1/notices/details?ids=" & Number.ToText(NoticeId) & "&format=json", [Headers=[#"Gen-Api-Key"="......"]])),
#"Converted to Table" = Record.ToTable(Source),
#"Expanded Value" = Table.ExpandListColumn(#"Converted to Table", "Value"),
#"Expanded Value1" = Table.ExpandRecordColumn(#"Expanded Value", "Value", {"id", "pipelineName", "pipelineId", "priorNoticeIdentifierId", "noticeIdentifierId", "priority", "type", "status", "subject", "body", "postDate", "effDate", "endDate", "insertDate"}, {"id", "pipelineName", "pipelineId", "priorNoticeIdentifierId", "noticeIdentifierId", "priority", "type", "status", "subject", "body", "postDate", "effDate", "endDate", "insertDate"})
in
#"Expanded Value1")
in
#"Added Custom"
---------------------------------------------------
Would really appreciate any help on this. Best, Sohana
Hi Anonymous : Also as I tried to change [deleted few steps & updated the expressions] the code in my previous query I posted today [to make it similar to your code snippet] as below
let
Source = Json.Document(Web.Contents("https://api.xyz.com/",
[
RelativePath="natgas/events/v1/notices",
Query=
[
priorities="critical",
limit="50",
offset="0",
format="json"
]
,
Headers=[
#"Gen-Api-Key"="...."
]
]
)),
data = Source[data],
#"Converted to Table" = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "pipelineName", "priority", "type", "subject", "postDate", "effDate", "endDate"}, {"id", "pipelineName", "priority", "type", "subject", "postDate", "effDate", "endDate"}),
id1 = #"Expanded Column1"[id],
#"Converted to Table1" = Table.FromList(id1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Custom" = Table.AddColumn(#"Converted to Table1", "Source", each Json.Document(Web.Contents("https://api.xyz.com/natgas/events/v1/notices/details?ids=" & [NoticeId] & "&format=json", [Headers=[#"Gen-Api-Key"="........."]])))
in
#"Added Custom"
---------------------------------------------------
I get Errors as below:
Any help would highly be appreciated.
-----------------------------------------------------------------
- Anonymous5 years agoNot applicable
Hi Anonymous,
What error that displayed in the custom column who invokes the web connector? Can you please share the detailed error messages?
After I checked your formula and snapshot, I found your id field values are stored in 'column1', so you need to use 'column1' to replace noticed. (you can also try to add 'relativepath' and other optional parameters into the web connector):
#"Added Custom" = Table.AddColumn(#"Converted to Table1", "Source", each Json.Document(Web.Contents("https://api.xyz.com/", [ Headers=[#"Gen-Api-Key"="...."], RelativePath="natgas/events/v1/notices/details", Query= [ ids=[Column1], format="json" ] ])))Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code
Regards,
Xiaoxin Sheng
- Anonymous5 years agoNot applicable
Hi Anonymous and all : Good day! Thanks for your continued support. I got the following error:
After I replace NoticeId with Column1, get the following error:
So, I started again and didn’t delete any steps. I renamed “Column1” as “NoticeId”, edited the #“Added Custom” part as below with Relative path and Query, created a variable, id to use in ids=[id]:
-------------------------
let
Source = Json.Document(Web.Contents("https://api.genscape.com/",
[
RelativePath="natgas/events/v1/notices",
Query=
[
priorities="critical",
limit="50",
offset="0",
format="json"
]
,
Headers=[
#"Gen-Api-Key"="f94ffe41c1d74066b90c564397edf9b2"
]
]
)),
data = Source[data],
#"Converted to Table" = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "pipelineName", "priority", "type", "subject", "postDate", "effDate", "endDate"}, {"id", "pipelineName", "priority", "type", "subject", "postDate", "effDate", "endDate"}),
id1 = #"Expanded Column1"[id],
#"Converted to Table1" = Table.FromList(id1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Custom" = Table.AddColumn(#"Converted to Table1", "Custom", each (NoticeId as number) => let
Source = Json.Document(Web.Contents("https://api.genscape.com/",
[
Headers=[#"Gen-Api-Key"="f94ffe41c1d74066b90c564397edf9b2"],
RelativePath=" natgas/events/v1/notices/details",
#"id"= Number.ToText(NoticeId),
Query=
[
ids=[id],
format="json"
]
])),
#"Converted to Table" = Record.ToTable(Source),
#"Expanded Value" = Table.ExpandListColumn(#"Converted to Table", "Value"),
#"Expanded Value1" = Table.ExpandRecordColumn(#"Expanded Value", "Value", {"id", "pipelineName", "pipelineId", "priorNoticeIdentifierId", "noticeIdentifierId", "priority", "type", "status", "subject", "body", "postDate", "effDate", "endDate", "insertDate"}, {"id", "pipelineName", "pipelineId", "priorNoticeIdentifierId", "noticeIdentifierId", "priority", "type", "status", "subject", "body", "postDate", "effDate", "endDate", "insertDate"})
in
#"Expanded Value1")
in
#"Added Custom"
--------------------------
Now I get the following with ‘function’ in each cell under ‘Custom’ Column
Not sure what to do?! Many thanks in advance.
- Anonymous5 years agoNot applicable
Hi Anonymous,
It seems like the power query not allow you direct do merge operations between different types(number and text), please try to use the following code of 'add custom column' step, I added text type convert in the formula.
#"Added Custom" = Table.AddColumn(#"Converted to Table1", "Source", each Json.Document(Web.Contents("https://api.xyz.com/", [ Headers=[#"Gen-Api-Key"="...."], RelativePath="natgas/events/v1/notices/details", Query= [ ids=Text.From([Column1]), format="json" ] ])))Regards,
Xiaoxin Sheng