Forum Discussion
TP-101
2 years agoHelper I
M Query Post REST API, return format not JSON with Expression.Error
I'm attempting a POST to a REST API which should return data in JSON. The POST appears to succeed however, receiving an Expression.Error trying to convert the response to binary. Can this query be ...
TP-101
2 years agoHelper I
Added the accept and still observing the same Expression.Error.
GetJsonQuery = Json.Document(Web.Contents("https://" & #"Tenant" & #"GetMetric", [Headers=[Authorization=AccessTokenHeader, #"accept"="application/json"], Content=Text.FromBinary(Json.FromValue(data))]))lbendlin
2 years agoSuper User
Try this.
GetJsonQuery = Json.Document(Web.Contents("https://" & Tenant & GetMetric, [Headers=[Authorization=AccessTokenHeader, Accept="application/json"], Content=Text.FromBinary(Json.FromValue(data))]))
You will also need to read up on RelativePath and Query.
- TP-1012 years agoHelper I
Changing it to that shows a Bad Request (400) error instead.
- lbendlin2 years agoSuper User
please show the current code.
- TP-1012 years agoHelper I
let data = "{ ""object_type"": ""device"", ""metric_category"": ""ssl_server"", ""metric_specs"": [ { ""name"": ""connected"" } ], ""object_ids"": ""[8589939089]"", ""cycle"": ""auto"", }", // Concatenates the Consumer Key & Consumer Secret and converts to base64 authKey = "Basic " & Binary.ToText(Text.ToBinary(#"API ID" & ":" & #"API Secret"),0), url = "https://" & #"Tenant" & #"Token URL", // Uses the oauth2/token method to obtain a bearer token GetJson = Web.Contents(url, [ Headers = [#"Authorization"=authKey, #"Content-Type"="application/x-www-form-urlencoded"], Content = Text.ToBinary("grant_type=client_credentials") ] ), FormatAsJson = Json.Document(GetJson), // Gets token from the Json response AccessToken = FormatAsJson[access_token], AccessTokenHeader = "Bearer " & AccessToken, // Uses the POST method using the bearer token from the previous POST oauth2/token method // GetJsonQuery = Json.Document(Web.Contents("https://" & #"Tenant" & #"GetMetric", [Headers=[Authorization=AccessTokenHeader, #"accept"="application/json"], Content=Text.FromBinary(Json.FromValue(data))])) GetJsonQuery = Json.Document(Web.Contents("https://" & Tenant & GetMetric, [Headers=[Authorization="AccessTokenHeader", Accept="application/json"]])) in GetJsonQuery