I need to send a curl request from powershell, using box api reference for help (I'm looking the the section called Update User
, but I'm having some trouble:
curl https://api.box.com/2.0/users/11111 -H @{"Authorization" = "token"} -d '{"name": "bob"}' -X PUT
Should update the user's name, but I get:
Invoke-WebRequest : A positional parameter cannot be found that accepts argument '{"name": "bob"}'. At G:\IT\bassie\Box\GetUsers.ps1:5 char:1 + curl https://api.box.com/2.0/users/892861590 -H @{"Authorization" = " ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I tried re-arranging it to
-d @{"name" = "bob"}
but the error changed to
Invoke-WebRequest : A positional parameter cannot be found that accepts argument 'System.Collections.Hashtable'. At G:\IT\bassie\Box\GetUsers.ps1:5 char:1 + curl https://api.box.com/2.0/users/892861590 -H @{"Authorization" = " ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
What do I need to put into the -d
parameter?
I managed to do what I needed with
So it seems that not only did I need to replace the
-D
parameter with-Body
, but I also had to specify theConteType
asapplication/json
in order to use that format.curl is an alias for PowerShell - Invoke-WebRequest, hence the error.
If you are trying to use real curl in PowerShell, then you must use curl.exe, or remove the curl alias from Invoke-WebRequest.
The errors are because passing parameters/arguments that Invoke-WebRequest has no idea what they are or what to do with the.
If you are trying to use external tools in PowerShell, then you have to fully qualify the UNC and name including the externtion, to them and remember that using external tools with PowerShell, this must be approached in a defined way.
For example:
See Using Windows PowerShell to run old command line tools (and their weirdest parameters) 'https://blogs.technet.microsoft.com/josebda/2012/03/03/using-windows-powershell-to-run-old-command-line-tools-and-their-weirdest-parameters'
See also this post regarding trying to use real curl with PowerShell.