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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
Super User
Super User

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors