I'm trying to set up a POST API call in Power BI, but the API has some requirements that are giving me trouble. One of the fields requires multiple inputs separated by commas, with each input surrounded by double quotes and the whole shebang enclosed in another set of double quotes. For example, a request may have this field set to "P12345","P23456". I've tested the formatting in Postman, but unfortunately I'm having trouble getting the follow up Json.Document line to parse in Power BI.
Here's the code I'm working with:
let
//API URL
URL = "https://some.url.com/api/download",
//Declare variables for the body of the POST request, convert to Query String
Body = " {""apikey"": ""keygoeshere"", ""format"": ""CSV"", ""partNumbers"": " & List.First(PartsList) & " }",
Parsed_JSON = Json.Document(Body),
BuildQueryString = Uri.BuildQueryString(Parsed_JSON),
//Send POST request
ZIPFile = Web.Contents(URL, [Headers=[#"Content-Type"="application/x-www-form-urlencoded"], Content = Text.ToBinary(BuildQueryString) ] ),
PartsList is a list of part numbers configured like I described in the first paragraph. For some reason I can't get the list of parts to be treated as a single value, and instead Power Query is grabbing the first set of double quotes and returning an invalid character error when it gets to the second. How can I get the query to treat the list of part numbers as a single value?
mmbr1606
9
Super User 2025 Season 1
SD-13050734-0
6
Rhys @ Empower 365
2