Forum Discussion
Json.Document Web.Content Swagger API
- 6 years ago
Hi
try this:
Source = Json.Document(Web.Contents("http://193.160.3.15:60003/api/Product?vpArticleNumbers=" & Text.From(vpArticleNumbers), [Headers=[Token="MYTOKEN"]])),In the syntax higlighting you will see that the first "vpArticleNumbers" will be considered as text, while the second (without quotes) will be regarded as the parameter from your function. It has to be converted as text for the Web.Contents-function.
But please be aware that this query will not refresh in the services as it is. Therefore you have to use the relative path parameter: http://blog.datainspirations.com/2018/02/17/dynamic-web-contents-and-power-bi-refresh-errors/
Hi patoduck ,
"How do I loop MYNUMBER?"
I don't quite understand what you want to achieve, please describe in more detail.
Best regards,
Lionel Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Here you have the code a bit more clearer.
I need to create MYNUMBER (a product number) a loop it, there I create a function, but I don't know how to put it outside the quotes in the WEB.Contents reference.
v-lionel-msft I have seen ImkeF doing this many times, but maybe I need more coffee to make it work.
let
Source = (vpArticleNumbers as MYNUMBER) as table => let
Source = Json.Document(Web.Contents("http://193.160.3.15:60003/api/Product?vpArticleNumbers=MYNUMBER", [Headers=[Token="MYTOKEN"]])),
Source1 = Source{0},
#"Converted to Table" = Record.ToTable(Source1),
#"Transposed Table" = Table.Transpose(#"Converted to Table"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"AlcoholPercent", Int64.Type}, {"AreaInfo", type any}, {"ArticleName", type text}, {"ArticleNumber", Int64.Type}, {"ArticleType1", type logical}, {"ArticleType2", Int64.Type}, {"Category1", type text}, {"Category2", type text}, {"CocktailDescription", type text}, {"Country", type text}, {"Description", type text}, {"District", type text}, {"ContainerCapacity", Int64.Type}, {"EANNumber", Int64.Type}, {"EPDNumber", Int64.Type}, {"FoodDescription", type text}, {"GrapeTypes", type text}, {"HorecaPrice1", type number}, {"HorecaPrice2", type number}, {"ImageFlag", type logical}, {"ImportedNumber1", type text}, {"ImportedNumber2", type text}, {"NextDelivery", Int64.Type}, {"ProducerDescription", type any}, {"ProducerName", type text}, {"ProducerURL", type text}, {"ProductionMethod", type text}, {"SalesLastMonth", Int64.Type}, {"SalesUnit", type text}, {"ServingTemperature", type text}, {"SoilInfo", type any}, {"SubDistrict", type text}, {"VecturaImageName", type text}, {"Volume", Int64.Type}, {"VPAllergens", type any}, {"VPArticleType", type text}, {"VPArticleDescription", type text}, {"VPArticleName", type text}, {"VPArticleNumber", Int64.Type}, {"VPArticleType2", Int64.Type}, {"VPBitterness", Int64.Type}, {"VPCertifications", type any}, {"VPColor", type text}, {"VPCorkType", type text}, {"VPPackagingType", type text}, {"VPRecommendedFoodSymbol1", type text}, {"VPRecommendedFoodSymbol2", type text}, {"VPRecommendedFoodSymbol3", type text}, {"VPFreshness", Int64.Type}, {"VPFullness", Int64.Type}, {"VPImageURL", type text}, {"VPIngredients", type text}, {"VPCategory", type text}, {"VPPrice", type number}, {"VPProducerID", type any}, {"VPSmell", type text}, {"VPStorageInfo", type text}, {"VPSweetness", Int64.Type}, {"VPTannin", Int64.Type}, {"VPTaste", type text}, {"VPVintage", type text}, {"VPEcological", type logical}, {"VPBiodynamic", type logical}, {"VPFairtrade", type logical}, {"VPEnviromentalsmart", type logical}, {"VPGluten", type logical}, {"VPKosher", type logical}, {"VPSugar", Int64.Type}, {"VPAcid", Int64.Type}, {"VPImporter", type text}, {"VPShopcategory", Int64.Type}, {"VPDistributor", type text}, {"VPMainGTIN", Int64.Type}, {"VPOtherGTINs", type text}, {"StockLevel", Int64.Type}, {"SaleYTD", Int64.Type}, {"SaleMTD", Int64.Type}, {"ActiveProduct20", type logical}, {"ActiveProduct21", type logical}, {"ActiveProduct22", type logical}, {"ActiveProduct23", type logical}, {"SaleStatusText20", type text}, {"SaleStatusText21", type text}, {"SaleStatusText22", type text}, {"SaleStatusText23", type text}, {"OrderedQuantityIB", Int64.Type}, {"SAPSaleStatus20", Int64.Type}, {"SAPSaleStatus21", Int64.Type}, {"SAPSaleStatus22", Int64.Type}, {"SAPSaleStatus23", Int64.Type}, {"SaleLYTD", Int64.Type}, {"SaleLYMTD", Int64.Type}, {"VPLaunchDate", type any}}),
#"Reordered Columns" = Table.ReorderColumns(#"Changed Type",{"ArticleNumber", "ArticleName", "Category2", "Category1", "AlcoholPercent", "AreaInfo", "ArticleType1", "ArticleType2", "CocktailDescription", "Country", "Description", "District", "ContainerCapacity", "EANNumber", "EPDNumber", "FoodDescription", "GrapeTypes", "HorecaPrice1", "HorecaPrice2", "ImageFlag", "ImportedNumber1", "ImportedNumber2", "NextDelivery", "ProducerDescription", "ProducerName", "ProducerURL", "ProductionMethod", "SalesLastMonth", "SalesUnit", "ServingTemperature", "SoilInfo", "SubDistrict", "VecturaImageName", "Volume", "VPAllergens", "VPArticleType", "VPArticleDescription", "VPArticleName", "VPArticleNumber", "VPArticleType2", "VPBitterness", "VPCertifications", "VPColor", "VPCorkType", "VPPackagingType", "VPRecommendedFoodSymbol1", "VPRecommendedFoodSymbol2", "VPRecommendedFoodSymbol3", "VPFreshness", "VPFullness", "VPImageURL", "VPIngredients", "VPCategory", "VPPrice", "VPProducerID", "VPSmell", "VPStorageInfo", "VPSweetness", "VPTannin", "VPTaste", "VPVintage", "VPEcological", "VPBiodynamic", "VPFairtrade", "VPEnviromentalsmart", "VPGluten", "VPKosher", "VPSugar", "VPAcid", "VPImporter", "VPShopcategory", "VPDistributor", "VPMainGTIN", "VPOtherGTINs", "StockLevel", "SaleYTD", "SaleMTD", "ActiveProduct20", "ActiveProduct21", "ActiveProduct22", "ActiveProduct23", "SaleStatusText20", "SaleStatusText21", "SaleStatusText22", "SaleStatusText23", "OrderedQuantityIB", "SAPSaleStatus20", "SAPSaleStatus21", "SAPSaleStatus22", "SAPSaleStatus23", "SaleLYTD", "SaleLYMTD", "VPLaunchDate"})
in
#"Reordered Columns"
in
Source
- patoduck6 years agoHelper III
let Source = (vpArticleNumbers as number) as table => let Source = Json.Document(Web.Contents("http://193.160.3.15:60003/api/Product?",vpArticleNumbers, [Headers=[Token="MYTOKEN"]])), Source1 = Source{0}, #"Converted to Table" = Record.ToTable(Source1),If i do this i get this error
- ImkeF6 years agoCommunity Champion
Hi
try this:
Source = Json.Document(Web.Contents("http://193.160.3.15:60003/api/Product?vpArticleNumbers=" & Text.From(vpArticleNumbers), [Headers=[Token="MYTOKEN"]])),In the syntax higlighting you will see that the first "vpArticleNumbers" will be considered as text, while the second (without quotes) will be regarded as the parameter from your function. It has to be converted as text for the Web.Contents-function.
But please be aware that this query will not refresh in the services as it is. Therefore you have to use the relative path parameter: http://blog.datainspirations.com/2018/02/17/dynamic-web-contents-and-power-bi-refresh-errors/
- patoduck6 years agoHelper III
Thanks ImkeF !
😍
let Source = (vpArticleNumbers as number) as table => let Source = Json.Document(Web.Contents("http://193.160.3.15:60003/api/Product?vpArticleNumbers="& Text.From(YOURNUMBER), [Headers=[Token="YOUR TOKEN"]])), Source1 = Source{0}, #"Converted to Table" = Record.ToTable(Source1), #"Transposed Table" = Table.Transpose(#"Converted to Table"), #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]) in #"Promoted Headers"