Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

MS PowerBI Rest error: Invoke-RestMethod : The 'Content-Type' header must be modified #5

Open
NancyAb opened this issue Jan 23, 2018 · 9 comments

Comments

@NancyAb
Copy link

NancyAb commented Jan 23, 2018

Hi,

I have PowerBI setup with a gateway and have been able to refresh the datasource using the MS tools.

I have customized the ps1 program with my company's settings and have installed the PowerShell tools.

When I run the manageRefresh.ps1 command, I get the errors:

Invoke-RestMethod : The 'Content-Type' header must be modified using the appropriate property or method.
Parameter name: name
At C:\temp\manageRefresh.ps1:78 char:1
+ Invoke-RestMethod -Uri $uri -Headers $authHeader -Method POST -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Invoke-RestMethod : The 'Content-Type' header must be modified using the appropriate property or method.
Parameter name: name
At C:\temp\manageRefresh.ps1:82 char:1
+ Invoke-RestMethod -Uri $uri -Headers $authHeader -Method GET -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Any ideas? Thanks in advance for looking. Nancy.

@BrightKnight6
Copy link

BrightKnight6 commented Feb 7, 2018

I am getting a similar error:

Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'â€Headers
System.Collections.Hashtable â€Method'.
At \PowerBI_Powershell_Script\Updated_Powershell_Script.ps1:119 char:1
+ Invoke-RestMethod -Uri $uri –Headers $authHeader –Method POST – ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

@BrightKnight6
Copy link

@NancyAb

I was getting the same error and these updates made my code work:
$authHeader = @{ Authorization=$token.CreateAuthorizationHeader() Content='application/json' }

and I believe the sample code mixes long and short dashes which was giving me an error as well so here is the modified code for that:
Invoke-RestMethod -Uri $uri -Headers $authHeader -Method POST -Verbose

@NancyAb
Copy link
Author

NancyAb commented Feb 14, 2018

Thanks so much. I will have a look. Nancy.

@sjt003001
Copy link

Hi,

I had the same issue and got an error with BrightKnight6 code too, but adding single quotes around Authorization and Content seemed to do the trick. So the key difference between the original and this is Content instead of Content-Type. I'm a newbie to all the concepts here so can't really explain why.

This is what I ended up with:

$authHeader = @{
'Authorization'=$token.CreateAuthorizationHeader()
'Content'='application/json'
}

Scott

@CorinnaAdkins
Copy link

CorinnaAdkins commented Mar 5, 2018

I consistently receive the error below and my dataset does not refresh, any help would be appreciated.
"
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:85 char:1

  • Invoke-RestMethod -Uri $uri –Headers $authHeader –Method POST –Verbose
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
    
    

VERBOSE: GET https://api.powerbi.com/v1.0/myorg/datasets/$datasetId/refreshes with 0-byte payload

@ashu16815
Copy link

ashu16815 commented Jul 12, 2018

HI All,

I am also getting :
PS C:\temp> .\sample.ps1
[Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult
System.Collections.Hashtable
Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'â?Headers
System.Collections.Hashtable â?Method'.
At C:\temp\sample.ps1:78 char:1

  • Invoke-RestMethod -Uri $uri â?"Headers $authHeader â?"Method POST â?"Verbose
  •   + CategoryInfo          : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand](url)
    
    

I tried all changes mentioned above but nothing worked. Please help

@chadtoney
Copy link

I'm also getting similar error:

Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'â€Headers System.Collections.Hashtable â€Method'.
At C:\Users\toneyc\Downloads\copyWorkspace.ps1:76 char:16

  • ... l_groups = (Invoke-RestMethod -Uri $uri –Headers $auth_header –Me ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
    • FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

sqlsauce added a commit to sqlsauce/powerbi-powershell that referenced this issue Nov 1, 2019
In issue Azure-Samples#5, it's pointed out in Azure-Samples#5 (comment) that the Invoke-RestMethod parameter names have long dashes, which causes problems. This changes the en dashes to dashes, which fixed the error.
@nickodemis99
Copy link

HI All,

I am also getting :
PS C:\temp> .\sample.ps1
[Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult
System.Collections.Hashtable
Invoke-RestMethod : A positional parameter cannot be found that accepts argument 'â?Headers
System.Collections.Hashtable â?Method'.
At C:\temp\sample.ps1:78 char:1

  • Invoke-RestMethod -Uri $uri â?"Headers $authHeader â?"Method POST â?"Verbose
  •   + CategoryInfo          : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException
      + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand](url)
    

I tried all changes mentioned above but nothing worked. Please help

You need to save you code to file that is not UTC. More than likely you copied code from a webpage and it include special characters that need to be removed.

You can always delete the problem line and retype it manually.

@Shailevy
Copy link

+1

Tried all suggestions and nothing worked.

@nickodemis99 The file was download via git, not a web browser

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants