Forum Discussion

MKE's avatar
MKE
Helper I
4 years ago
Solved

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)
                                                        ]
                          )
            )

>

2 Replies