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
Ryder
Frequent Visitor

Converting Postman Request to run directly from PowerBI

Hey All,

 

This is an ongoing issue i've been trying to solve to remove the postman step from my powerBI process.

I'm an analyst not a coder so getting the syntax correct to run this request directly from powerBI is a bit over my head.

 

Here's the working request via postman:

 

POST /api/reports/query HTTP/1.1
Host: api.ongage.net
X_USERNAME: username
X_PASSWORD: password
X_ACCOUNT_CODE: accountcode
Content-Type: text/plain

{
"select":[
"mailing_name",
[
"MAX(`stats_date`)",
"stats_date"
],
"sum(`sent`)",
"sum(`success`)",
"sum(`failed`)",
"sum(`opens`)",
"sum(`unique_opens`)",
"sum(`unsubscribes`)",
"sum(`complaints`)",
"sum(`clicks`)",
"sum(`unique_clicks`)",
"mailing_id",
"list_id",
"from_address",
"email_message_subject",
"schedule_date"
],

"from":"mailing",
"group":[
"list_id",
"mailing_id"
],
"list_ids" : "all",
"get_extra_conversion_points":true,
"filter":[
[
"stats_date",
">=",
"2020-01-01"
],
[
"stats_date",
"<=",
"2020-12-30"
]
]
}

 

And an attempt at converting the code thanks to @tonmcg :

I'm hoping someone can tweak the code below so it can run from PBI:

 

let
    username = "",
    password = "",
    accountcode  = "",
    bodyContent = [
        select = {
            "mailing_name",
            {
                "MAX('stats_date')",
                "stats_date"
            },
            "sum('sent')",
            "sum('success')",
            "sum('failed')",
            "sum('opens')",
            "sum('unique_opens')",
            "sum('unsubscribes')",
            "sum('complaints')",
            "sum('clicks')",
            "sum('unique_clicks')",
            "mailing_id",
            "list_id",
            "from_address",
            "email_message_subject",
            "schedule_date"
        },
        from = "mailing",
        group = {
            "list_id",
            "mailing_id"
        },
        list_ids = "all",
        get_extra_conversion_points = true,
        filter = {
            {
                "stats_date",
                ">=",
                "2020-01-01"
            },
            {
                "stats_date",
                "<=",
                "2020-12-30"
            }
        }
    ],
    binaryContent = Json.FromValue(bodyContent),
    request = Web.Contents(
        "api.ongage.net",
        [
            Headers = [
                #"X_USERNAME" = username,
                #"X_PASSWORD" = password,
                #"X_ACCOUNT_CODE" = accountcode,
                #"Content-Type" = "text/plain"
            ],
            RelativePath = "/api/reports/query",
            Query = [],
            Content = binaryContent
        ]
    )
in
    request

 

Any help on this is greatly appreciated.

Thank you all. 

4 REPLIES 4
tonmcg
Resolver II
Resolver II

Your code looks beautiful. What's the problem you're encountering?

Ryder
Frequent Visitor

Hey @tonmcg - thank you for following up. I really appreciate your help on this.

 

When I enter the code in powerquery as is via the advanced error and populate the header info - I receive the following error:

 

DataSource.Error: Web.Contents failed to get contents from 'http://api.ongage.net/api/reports/query' (412): Precondition Failed
Details:
DataSourceKind=Web
DataSourcePath=http://api.ongage.net/api/reports/query
Url=http://api.ongage.net/api/reports/query

 

Use `https` instead of `http`, meaning change the first parameter of `Web.Contents` to "https://api.ongage.net", like so:

 

request = Web.Contents(
        "https://api.ongage.net",
        [
            Headers = [
                #"X_USERNAME" = username,
                #"X_PASSWORD" = password,
                #"X_ACCOUNT_CODE" = accountcode,
                #"Content-Type" = "text/plain"
            ],
            RelativePath = "/api/reports/query",
            Query = [],
            Content = binaryContent
        ]
    )

 

See if that helps.

Ryder
Frequent Visitor

Ok - so when running the code with https the inital error message reads:

 

DataSource.Error: Web.Contents with the Content option is only supported when connecting anonymously.
Details:
DataSourceKind=Web
DataSourcePath=https://api.ongage.net/api/reports/query

 

Then when changing the permissions under data source setting to anonymous - the error is as follows:

 

DataSource.Error: Web.Contents failed to get contents from 'https://api.ongage.net/' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=https://api.ongage.net/
Url=https://api.ongage.net/

 

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.