Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

How to PUT multipart/form-data in PowerShell using Invoke-RestMethod

$
0
0

I am trying to transform a curl command for uploading new DNS zone files in NSONE to  Powershell using Invoke-RestMethod.

NSONE has posted this sample curl command:

curl -X PUT -F zonefile=@example.com.db -H 'X-NSONE-Key: qACMD09OJXBxT7XOuRs8' https://api.nsone.net/v1/import/zonefile/example.com

which I partially cloned to its Powershell version as

Invoke-RestMethod -Uri https://api.nsone.net/v1/import/zonefile/example.com -Header @{"X-NSONE-Key" = "qACMD09OJXBxT7XOuRs8"} -Method Put -InFile "c:\example.com.db" -ContentType "multipart/form-data"

Obviously, I am doing something wrong here because I am getting this error:

"Invoke-RestMethod : {"message":"Upload a single zone file using multipart/form-data and input name \"zonefile\""}
CategoryInfo: InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
FullyQualifiedErrorId: WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
"

Any suggestion would be very much appreciated.

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles