Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
MKE
Helper I
Helper I

Passing a string variable in a POST request payload/body

Hello guys,

 

I have a variable "Id" that I am passing in a payload as shown below. "Id" is a string value like "LASST390000000000003". If I hardcode it, it works but once I pass it in as a variable it fails to work. I will appreciate some help here.

 

</

let

url = "https://api.bls.gov/publicAPI/v1/timeseries/data/",
Id = Locations[Location]{0},
body = "{""seriesid"":"& Id &",""startyear"":""2017"", ""endyear"":""2022""}",  ---------Does not work

body = "{""seriesid"": [""LASST390000000000003""],""startyear"":""2017"", ""endyear"":""2022""}", --------Works
Source = Json.Document(
                         Web.Contents(
                                             url,
                                              [
                                        Headers = [#"Content-Type"="application/json"],
                                        Content = Text.ToBinary(body)
                                                        ]
                          )
            )

>

1 ACCEPTED SOLUTION

Hi Vijay_A_Verma, thanks for your input. Unfortunatey that couldn't pass in the Id as expected. Howerver, I cracked it following my reference to this resource:

https://community.powerbi.com/t5/Power-Query/Passing-Variables-in-API-Post-Request-JSON-Body/m-p/529...

 

The solution is:

Id = Text.Combine({"[""",Locations[Location]{0},"""]"},""), ----- Crazy string concatenation here
body = "{""seriesid"":"&Id&",""startyear"":""2017"", ""endyear"":""2022""}", ----referencing it here

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Use this for body

body = "{""seriesid"":[""&id&""], ""startyear"":""2010"", ""endyear"":""2012""}"

Hi Vijay_A_Verma, thanks for your input. Unfortunatey that couldn't pass in the Id as expected. Howerver, I cracked it following my reference to this resource:

https://community.powerbi.com/t5/Power-Query/Passing-Variables-in-API-Post-Request-JSON-Body/m-p/529...

 

The solution is:

Id = Text.Combine({"[""",Locations[Location]{0},"""]"},""), ----- Crazy string concatenation here
body = "{""seriesid"":"&Id&",""startyear"":""2017"", ""endyear"":""2022""}", ----referencing it here

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors