Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
I'm attempting to POST a JSON payload to a REST API that will return JSON data. I'm running into an Expression.Error "We cannot convert the value <myJSON> to type Binary". (screenshot). Via "Content=", I've tried various permutations but cannot get it to successfully POST.
To POST to a REST API, does the JSON payload have to be binary? If not, how can the "Content=" be crafted such that it doesnt try to convert to binary? I've tried Content=Text.FromBinary(Json.FromValue(data) to no avail.
Error
The entire M Query
let
data = "{
        ""object_type"": ""device"",
        ""metric_category"": ""ssl_server"",
        ""metric_specs"": [
                {
                ""name"": ""connected""
                }
            ],
        ""object_ids"": ""[8589939089]"",
        ""cycle"": ""auto"",
    }",
payload = Json.Document(data),
 // 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], Content=(data)]))
in
    GetJsonQuery
I agree with @amitchandak to not convert it to binary.
Also, if you want Power Query to send a POST request and not a GET request (which it basically always tries to do) you need to specify the body of the request.
Yes and I'm using "Content=" to POST, not GET. The body, or JSON payload is defined in the above M query. Do you see anything that does not look correct?
Previously, I was using this:
Content=Text.FromBinary(Json.FromValue(data))
And that produced a different error, which appears to be malformed:
Focusing on just this line, I'm not converting to binary, unless that is the default behavior. Is there a way to force Content to not convert?
GetJsonQuery = Json.Document(Web.Contents("https://" & #"Tenant" & #"GetMetric", [Headers=[Authorization=AccessTokenHeader], Content=(data)]))
Anyone have other guesses as to why I'm unable to POST this JSON payload without it trying to convert to binary? This is blocking an important project.
 
					
				
				
			
		
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
 
            | User | Count | 
|---|---|
| 84 | |
| 49 | |
| 36 | |
| 31 | |
| 30 |