Forum Discussion
API call with JSON formatted body
- 2 years ago
Actually managed to get this sorted myself, thanks anyway
- 2 years ago
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""}]}"
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
Sourceand the authreponse is then called later.
Does that help you?