cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gcyr Frequent Visitor
Frequent Visitor

Specified value has invalid HTTP Header characters

Hi,

 

I trying to connect to a secure API using a token and I received the following error:

 

Expression.Error: Specified value has invalid HTTP Header characters.
Parameter name: name
Details:
<Token>

 

Here is my Query :

let
apiUrl = "<ApiUrl>",
options = [Headers =[#" token "= "<Token>"], Query=[#" SQLQuery "=" <SqlQuery> "]],
result = Web.Contents(apiUrl , options)
in
result

 

The characters in my Token are alphanumeric.

 

How do I resolve this error.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
gcyr Frequent Visitor
Frequent Visitor

Re: Specified value has invalid HTTP Header characters

Hi @v-jiascu-msft

 

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
result

The 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

View solution in original post

3 REPLIES 3
v-jiascu-msft Super Contributor
Super Contributor

Re: Specified value has invalid HTTP Header characters

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

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
gcyr Frequent Visitor
Frequent Visitor

Re: Specified value has invalid HTTP Header characters

Hi @v-jiascu-msft

 

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
result

The 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

View solution in original post

Highlighted
Kieran
Advisor

Re: Specified value has invalid HTTP Header characters

Extremely helpful you are a star Smiley Happy

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 373 members 3,469 guests
Please welcome our newest community members: