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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
trevrobwhite
Advocate I
Advocate I

Post JSON without PowerBI Reformatting it

I need to send this post data to an API endpoint:

{
    "limit": 5,
    "detailed": "true",
    "policy.complianceStandard": "Scope 2021",
    "timeRange": {
        "type": "to_now",
        "value": "EPOCH"
    },
    "filters": [
        {
            "name": "alert.status",
            "operator": "=",
            "value": "open"
        }
    ]
}

 

I tried formatting this as an array as it looked nicer in my code, but M doesn't seem to like my filters object, the only way I seem to be able to get a single element array with an object in it was to give it a key of 0 but then the remote server gave me a 400 bad request, so I went for the manual approach.

 

        alertPayload = "{
            ""limit"": 10,
            ""detailed"": ""true"",
            ""policy.complianceStandard"": ""Scope 2021"",
            ""timeRange"": {
                ""type"": ""to_now"",
                ""value"":""EPOCH""
            },
            ""filters"": [
                {
                    ""name"": ""alert.status"",
                    ""operator"": ""="",
                    ""value"": ""open"" 
                }
            ]
        }",

        
        responseAlert = Web.Contents("https://api.io/v2/alert", [
            Headers = [
                #"Content-Type" = "application/json",
                #"x-redlock-auth" = token
            ],
            Content = Text.FromBinary(alertPayload)
        ]),

 

If I give alertPayload directly to content it complains, but if I surround it with Text.FromBinary or JSON.FromValue then the remote webserver gives me a 400 bad request indicating M has changed something, is there a way to say post this text to the web server and tell M don't change it or that it's pre-formatted?

 

Thanks in advance.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

You are supposed to use Text.ToBinary, not Text.FromBinary.

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

You are supposed to use Text.ToBinary, not Text.FromBinary.

Many thanks for this, I think I tried so many things over many days I kept this error in, I installed fiddler and got a bit further, the posted JSON appears to be valid.

 

What's happening is becuase I have:

Prisma = [
    Authentication = [ 
        UsernamePassword = [
            UsernameLabel = "API User",
            PasswordLabel = "API Password"
        ]
    ],
    Label = "Data Connector"
];

Power Query is adding a header:

Authorization: Basic XXXX

 

The remote webserver is replying:

message=request has different values in X-Redlock-Auth and Authorization, unclear which to use.

 

It doesn't understand why I'm sending over an API key and setting the Authorization header to basic.

 

Is there a way to remove Authorisation from the header or change my inputs so I can ask the end user for a username / password (this is how I get the login key) but don't set the header?

 

API Doc: https://docs.paloaltonetworks.com/prisma/prisma-cloud/prisma-cloud-admin/get-started-with-prisma-clo... 

Just an update, I got it to work (thanks for the advice), sharing for completeness

 

I needed:

ManualCredentials = true

 

In the request.

        responseAlert = Web.Contents("https://api.io/v2/alert", [
            Headers = [
                #"Content-Type" = "application/json",
                #"x-redlock-auth" = token
            ],
            Content = Text.ToBinary(alertPayload),
            ManualCredentials = true
        ]),

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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