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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Breticious
Helper I
Helper I

Passing Variables in API Post Request JSON Body

I am looking to make a semi-flexible template where the user punches in their own personal credentials into the JSON body being passed into my GET. I want to replace the [username parameter] and [password parameter] with the value in the parameter without having to include the quotation (") or double quotation inside the request. Help! Here is the BODY variable that I'm talking about:

BODY = "{
        	""UserName"":""[username parameter]"",
        	""Password"":""[password parameter]""
        }"

Help! Anyone!

1 ACCEPTED SOLUTION
Breticious
Helper I
Helper I

Ok. I figured it out. I had to use an annoying text combination:

let
    LOGIN = Text.Combine({"""",Login_Parameter,""""},""),
    PW = Text.Combine({"""",Login_Password,""""},""),
    body = "{
        	""UserName"":"&LOGIN&",
        	""Password"":"&PW&"
        }",

Just to reiterate, the parameters I setup are named Login_Parameter and Login_Password and formatted as Text. The result comes out as:

body = {
        	"UserName":"breticious",
        	"Password":"password123"
        }

View solution in original post

4 REPLIES 4
Breticious
Helper I
Helper I

Ok. I figured it out. I had to use an annoying text combination:

let
    LOGIN = Text.Combine({"""",Login_Parameter,""""},""),
    PW = Text.Combine({"""",Login_Password,""""},""),
    body = "{
        	""UserName"":"&LOGIN&",
        	""Password"":"&PW&"
        }",

Just to reiterate, the parameters I setup are named Login_Parameter and Login_Password and formatted as Text. The result comes out as:

body = {
        	"UserName":"breticious",
        	"Password":"password123"
        }

can this be used to resolve the following substitution for parameters?

 

 

let
dateRangeStart=dateRangeStart,
dateRangeEnd=dateRangeEnd,
body = "{ ""dateRangeStart"": ""2022-01-01T00:00:00.000"", ""dateRangeEnd"": ""2022-12-01T23:59:59.000"", ""detailedFilter"": { ""page"": ""1"", ""pageSize"": ""500"" } }", Source = Json.Document

v-yuezhe-msft
Employee
Employee

@Breticious,

What Power Query code do you use to connect to the API in Power BI Desktop? I am not very sure about the requirement that " want to replace the [username parameter] and [password parameter] with the value in the parameter ". Could you please explain it?

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Sorry for the late response, @v-yuezhe-msft  but I'm not sure I follow what you are asking. 

 

I am using Mashup in the Advanced Editor of Power BI to directly connect to a RESTFUL API that uses JSON objects to pass things back and forth. It requires an authentication token.

 

It was a giant pain in the rear and took a LOT of work to pass everything just right. Does that answer your question?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors