Forum Discussion
GET Request and Token authentication to download file as JSON
- 6 years ago
Query parameters and header information can be part of the Web.Contents call. The last URL shows the examples.
https://docs.microsoft.com/en-us/powerquery-m/web-contents
https://docs.microsoft.com/en-us/power-query/web.contents
https://kohera.be/blog/power-bi/the-hidden-gems-of-the-function-web-contents/
- Anonymous6 years ago
Hi Anonymous,
You can try to use the following code if it meets your requirement:
let GetJson = Web.Contents( "https://xxxxxxxx/api", [ RelativePath="/v1.0/data/search", Query= [ query="xxxxxxx", limit=1000 ] ] ), FormatAsJson = Json.Document(GetJson) in FormatAsJsonReference links:
Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code
Get Data from Twitter API with Power Query
Regards,
Xiaoxin Sheng
Hi ,
This is what i am actually looking for. This worked for me. Thanks a lot and sorry for late reply.
There is a limit of 1000 records. But we have around 2300 records . So how do we neeed to execute the next statement to get remaining records . I tried something but it isnt working . Could you please help me ? Below is the M-query i am using to get all the records and not just 1000 records.
let
Source = Json.Document(Web.Contents("URL", [Headers=[Accept="application\json", Authorization="Bearer myToken"]])),
#"ExplodeTable" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"ExpandResults" = Table.ExpandRecordColumn(#"ExplodeTable"[results], "Column1", {"Name", "Software Type"}, {"Name", "Software Type"}),
#"GatherNext" = Table.AddColumn(#"ExplodeTable", "NextValue", each if #"ExplodeTable".[Next] <> null then Json.Document(Web.Contents(#"ExplodeTable"[Next], [Headers=[Accept="application/json", Authorization="Bearer Mytoken"]]) else null)
in
#"GatherNext"
Thanks,
Venkatesh
Your problem is not the [next] statement but the Source statement. Either use a recursive function to collect all headers, or if you know the list size then make three calls, with offset 0, 1000, and 2000, and merge the results.