Forum Discussion
Specified value has invalid HTTP Header characters
- 8 years ago
I found a solution to my problem.
There was a couple of issues:
My code should have been
let
apiUrl = " <APIURL>",
SqlQuery = " <SQL Query> "
options = [Headers =[Token="<Token>", #"Content-Type" = "application/json"], Content = Text.ToBinary(SqlQuery)],
result = Web.Contents(apiUrl , options)
in
resultThe Token should not have been in "". I don't know why HTTP did not recognize this header.
The API only accepts POST method, so my SQLQuery should have been submitted as Content.
I also had to specify the Content-Type.
Thanks,
Guillaume
Hi gcyr,
The error message said there was something wrong with Parameter Names. I searched this web and found that #" token " isn't a valid header option. Maybe you can try this:
let apiUrl = "<ApiUrl>", options = [Headers =[Authorization= "<Token>"], Query=[#" SQLQuery "=" <SqlQuery> "]], result = Web.Contents(apiUrl , options) in result
Or you can try it in this format.
let
authKey = "Bearer token",
url = "https://api.powerbi.com/......",
GetJson = Web.Contents(url,
[
Headers = [#"Authorization"=authKey,
#"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"]
]
),
content = Json.Document(GetJson),
value = content[value],
#"Converted to Table" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "name", "addRowsAPIEnabled"}, {"Column1.id", "Column1.name", "Column1.addRowsAPIEnabled"})
in
#"Expanded Column1"
Best Regards!
Dale
- gcyr8 years agoFrequent Visitor
I found a solution to my problem.
There was a couple of issues:
My code should have been
let
apiUrl = " <APIURL>",
SqlQuery = " <SQL Query> "
options = [Headers =[Token="<Token>", #"Content-Type" = "application/json"], Content = Text.ToBinary(SqlQuery)],
result = Web.Contents(apiUrl , options)
in
resultThe Token should not have been in "". I don't know why HTTP did not recognize this header.
The API only accepts POST method, so my SQLQuery should have been submitted as Content.
I also had to specify the Content-Type.
Thanks,
Guillaume
- Kieran7 years agoAdvocate II
Extremely helpful you are a star :smileyhappy: