Push/upload nuget packet using Invoke-WebRequest

Hi Guys,

I have been trying to push the nuget packet using Invoke-WebRequest post method but I am getting authentication errors even though I am using right api key. Can you please help me to solve this issue. Here is the cmdlet I have been trying.

Invoke-WebRequest -Uri http://localhost/api/packages/raw?replace=false -Headers @{ “x-api-key”=“API-XXXXXXXXXXXXXXXXXXX” } -Method Post -InFile $FilePath -ContentType ‘multipart/form-data’

Thanks for your help.

Hi Ajay,

Thanks for getting in touch! What error are you getting? And what version of Octopus are you using? This feature is only available in our 3.3.0-beta.


Thanks for the reply. I installed version 3.2.22. So, is this version does not support the invoke-Webrequest? Following is the error I am getting.

Invoke-WebRequest : The remote server returned an error: (401) Unauthorized.
At line:8 char:10

  • $upload= Invoke-WebRequest -Uri http://localhost/api/packages/raw?replace=false
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-We 
     bRequest], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRe 


Hi Vanessa,

I have also tried same command on Octopus version 3.3.0-beta, throwing same authentication error.

Hi Ajay,

May I ask why are you trying to push the package with invoke-webrequest instead of using Nuget.exe? That Powershell cmdlet can be a bit tricky when it comes to uploading files.

You might also wanna check this LinqPad that my friend Teammate Mike wrote to push packages over HTTP, which proved to be more reliable than nuget.exe itself.


HI Dalmiro,

we are feeling like nuget.exe taking considerable time to push the packets and trying to implement invoke-webrequest post using inbuilt octopus API’s in the hope of time taking might come down. All other scripts we have implemented are in powershell, so we want to use powershell for this one as well. Is it possible to get powershell script for this operation?


Hi Ajay,

Sorry for the delay here. I’ve tried to write a script for this today using invoke-webrequest but I didn’t had any luck.

One of our devs wrote this LinqPad script to push a package using http that proved to be faster than nuget. Perhaps you can use it or translate it to Powershell to achieve what you need: https://github.com/OctopusDeploy/OctopusDeploy-Api/blob/master/Octopus.Client/LINQPad/Push%20Package%20to%20Built-In%20Repository.linq

Best regards,

Hi again Ajay,

In Octopus 3.3 you’ll also be able to push packages using the following powershell snippet

$url = "http://OctopusServer/api/packages/raw?apiKey=API-OCTOPUSUSERAPIKEY"
$filePath = "C:\PathToFile\AspNetCoreWebApp.1.0.0.zip" #this could also be a .nupkg
$wc = new-object System.Net.WebClient
$wc.UploadFile($url, $filePath)


Thanks Dalmiro.

I will try that.thanks