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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Jules88
New Member

API call with JSON formatted body

Hello,

 

I am looking for a little help with regards to an API call I am trying to make and I cannot quite get it to work.

 

 

let

    AccessToken="Bearer "&GetAuthToken(),

    url="https://gateway.qg2.apps.qualys.eu/rest/2.0/search/am/asset",

    body = "
        {
            ""filters"":
            [
                {
                ""field"":""software.name"",
                ""operator"":""contains"",
                ""value"":""Chrome""
                }
            ]
        }",

    headers=[#"Content-Type"="application/json",#"X-Requested-With"="PowerBi",#"Accept"="*/*",Authorization=AccessToken],

    Source = Web.Contents(url,[Content=Text.ToBinary(body),Headers=headers,Query=[#"includeFields"="hardware"]]),

 

 

If I use powershell, I can get this to work using a similar format. 

 

 

#Create our search criteria.
$body = @"
{
    "filters": [
    {
    "field": "software.name",
    "operator": "CONTAINS",
    "value": "Chrome"
    }
    ]
   }
"@

#Now we will go and get the first set of records
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("X-Requested-With", "Postman")
$headers.Add("Content-Type", "application/json")
$headers.Add("Accept", "*/*")
$headers.Add("Authorization", "Bearer "+ $authtoken)

$response = Invoke-RestMethod 'https://gateway.qg2.apps.qualys.eu/rest/2.0/search/am/asset?includeFields=hardware' -Method 'POST' -Headers $headers -Body $body

 

 

I suspect I have done something silly or made a typo, but I just cannot get this to work in PowerBi. I keep getting a http 400 error.

 

DataSource.Error: Web.Contents failed to get contents from 'https://gateway.qg2.apps.qualys.eu/rest/2.0/search/am/asset?includeFields=hardware' (400): Bad Request
Details:
DataSourceKind=Web
DataSourcePath=https://gateway.qg2.apps.qualys.eu/rest/2.0/search/am/asset
Url=https://gateway.qg2.apps.qualys.eu/rest/2.0/search/am/asset?includeFields=hardware

 

Any insight would be hugely appreciated.

 

Thanks

 

John

2 ACCEPTED SOLUTIONS
Jules88
New Member

Actually managed to get this sorted myself, thanks anyway

View solution in original post

Jules88
New Member

The code itself appeared to be correct, maybe it was the formatting that needs to be all on one line, but the operator is case sensitive, has to be in capitals, certainly for the API call I was using anyway.

 

    body="{ ""filters"": [{""field"":""software.name"", ""operator"":""EQUALS"", ""value"":""Chrome""}]}"

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hello,

I'm trying to get the Bearer Token from Qualys API, I've seen that you have already done this with function

GetAuthToken()

This is my script

let
url = "https://gateway.qg2.apps.qualys.eu/auth",
headers = [#"Authorization" = "Bearer {{authTokenValue}}",#"Content-Type" = "application/x-www-form-urlencoded", #"Accept" = "*/*", #"X-Requested-With"="QualysPostman"],
postData = Json.FromValue(
[
#"username" = "xxxxx",#"password" = "xxxx",#"token" = "true"
]),
response = Web.Contents(url,
[
Headers = headers,
Content = postData
]),
jsonResponse = Json.Document(response)
in
jsonResponse

 

but I receive teh following error message: 

DataSource.Error: Impossibile per Web.Contents ottenere il contenuto da 'https://gateway.qg2.apps.qualys.eu/auth' (500): Internal Server Error
Dettagli:
DataSourceKind=Web
DataSourcePath=https://gateway.qg2.apps.qualys.eu/auth
Url=https://gateway.qg2.apps.qualys.eu/auth

 

Could you help me to solve the problem?

Thanks in advance

 

Francesco

Hello fmagli,

 

Sorry for the delay in replying.

 

I think you are calling the Auth API to get the bearer token, so you shouldn't need the Authorization header at this stage, that would be used when you are calling other API's for data.

 

My authtoken looks like

 

let
    Source = () => let

        Source = Text.FromBinary(Web.Contents("https://gateway.qg2.apps.qualys.eu/auth",
            [
                Headers=[#"Content-Type" = "application/x-www-form-urlencoded"],
                Content = Text.ToBinary("username=xxxxxxx&password=xxxxxxxx&token=true")
            ])),
        AuthResponse=Json.Document(Source)
        
    in
        Source
in  
    Source

and the authreponse is then called later.

 

Does that help you? 

Jules88
New Member

The code itself appeared to be correct, maybe it was the formatting that needs to be all on one line, but the operator is case sensitive, has to be in capitals, certainly for the API call I was using anyway.

 

    body="{ ""filters"": [{""field"":""software.name"", ""operator"":""EQUALS"", ""value"":""Chrome""}]}"
Jules88
New Member

Actually managed to get this sorted myself, thanks anyway

Anonymous
Not applicable

Hi @Jules88 ,

Glad to hear you resolved the issue yourself!
By the way, maybe there are other users who are facing the same problem as you, could you please post your solution below and accept it as a solution, it will make it easier for other users to find the answer faster, thanks!

Best Regards,
Dino Tao

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors