Forum Discussion
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 modified to return the data as JSON and not convert to binary? I'm assuming it's something with line 31. Thank you in advance.
Expression.Error
The entire M query
18 Replies
- lbendlinSuper User
The response is JSON, just a bit messed up . \u000a is a line feed. \" is a double quote etc. You can make that usable with a couple of replaces.
Anyway, in your headers you can specify which content type you accept. Try setting that to application/JSON.
- TP-101Helper I
Thank you lbendlin . I changed line 31 to include a content-type however, still seeing the Expression.Error. I'm not sure what is tring to convert to binary since the response should be json. Any idea?
GetJsonQuery = Json.Document(Web.Contents("https://" & #"Tenant" & #"GetMetric", [Headers=[Authorization=AccessTokenHeader, #"Content-Type"="application/json"], Content=Text.FromBinary(Json.FromValue(data))]))- lbendlinSuper User
Try adding an accept directive.
- TP-101Helper 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))]))
- lbendlinSuper User
Can you post a sample result of Web.Contents ?
- TP-101Helper I
Is this what you are looking for? The variables form a complete https URL to the endpoint. Screenshot 1. Then, we're posting some JSON data to the endpoint. Screenshot 2.
Then it should return JSON data. By the look of the Expression.Error, it appears to be data I'm POST'ing that it's trying to first convert to binary. I'm wondering if the "Content=Text.FromBinary" is the culpret. I dont believe there is a "Text.FromJSON" equivalent.
- lbendlinSuper User
no, I am looking for a sample response text with the \u000a etc.