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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jm420a
Frequent Visitor

HTTP POST To API for query source - Passing Parameters to API using Power Automate POST URL

Greetings, I have an API Call that works fine in Postman when specifiying parameters, however, when I try to post to the same URL, passing the parameters in PQ, I receive a 400 Bad Request error. I'm inclined to believe it is the syntax of my PQ, however, I am stuck as to where / what it may be. 

Sample code below: 

let
    
    PostURL = "https://prod-59.westus.logic.azure.com:443/workflows/281583e6ee6b45d6705dfaa8531/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=W1O8t6yfYjcXLPsmKZdmE7PsvxFWtZUjz2miFY"
    , AccessKey2 = "aaaaa-bbbbb-ccccc-ddddd-eeeee"
    , TenantURL2= "https://yourtenant.sharepoint.com"

    , Source = Json.Document(
                    Web.Contents(
                        PostURL    
                        , [Headers=[#"content-type"="application/json"]
                        , Content = 
                            Json.FromValue(
                                {[AccessKey=AccessKey2,TenantURL=TenantURL2]}
                                )
                           ]
                                )
                              )   

    in Source

 

The above code does not work in PQ, however, the below Postman code snippet for http POST works okay. 

I'm pretty sure it is how I'm passing the Content Parameters, but I'm not sure where my error is. 

Postman code:

POST /workflows/281583e6ee6b4b6705dfaa8531/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=W1O8t6yfYfgXLPsmKZdmE7PsvxFWtZUjz2miFY HTTP/1.1
Host: prod-59.westus.logic.azure.com:443
Content-Type: application/json
Content-Length: 112

{
"AccessKey": "aaaaa-bbbbb-ccccc-ddddd-eeeee",
"TenantURL": "https://yourtenant.sharepoint.com"

}
1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @jm420a ,
yes, you are mixing M- and JSON-syntax here: 
In M, a record is defined using square brackets instead of curly ones in JSON.
And when using the Json.FromValue-function, you have to pass M-code to it.
So removing the curly brackets in there, should hopefully do the trick:

let
    
    PostURL = "https://prod-59.westus.logic.azure.com:443/workflows/281583e6ee6b45d6705dfaa8531/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=W1O8t6yfYjcXLPsmKZdmE7PsvxFWtZUjz2miFY"
    , AccessKey2 = "aaaaa-bbbbb-ccccc-ddddd-eeeee"
    , TenantURL2= "https://yourtenant.sharepoint.com"

    , Source = Json.Document(
                    Web.Contents(
                        PostURL    
                        , [Headers=[#"content-type"="application/json"]
                        , Content = 
                            Json.FromValue(
                                [AccessKey=AccessKey2,TenantURL=TenantURL2]
                                )
                           ]
                                )
                              )   

    in Source

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

2 REPLIES 2
ImkeF
Community Champion
Community Champion

Hi @jm420a ,
yes, you are mixing M- and JSON-syntax here: 
In M, a record is defined using square brackets instead of curly ones in JSON.
And when using the Json.FromValue-function, you have to pass M-code to it.
So removing the curly brackets in there, should hopefully do the trick:

let
    
    PostURL = "https://prod-59.westus.logic.azure.com:443/workflows/281583e6ee6b45d6705dfaa8531/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=W1O8t6yfYjcXLPsmKZdmE7PsvxFWtZUjz2miFY"
    , AccessKey2 = "aaaaa-bbbbb-ccccc-ddddd-eeeee"
    , TenantURL2= "https://yourtenant.sharepoint.com"

    , Source = Json.Document(
                    Web.Contents(
                        PostURL    
                        , [Headers=[#"content-type"="application/json"]
                        , Content = 
                            Json.FromValue(
                                [AccessKey=AccessKey2,TenantURL=TenantURL2]
                                )
                           ]
                                )
                              )   

    in Source

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

jm420a
Frequent Visitor

Thanks @ImkeF . It was that, as well as a typo in the JSON payload. I stretched my pinky too far and typed | instead of } when I was closing the JSON out at the source. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Kudoed Authors