ThePoShWolf/Curl2PS

Unable to conver the following Curl to Powershell

Closed this issue · 2 comments

curl command

curl -X PUT --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \ "name": "vRops", \ "password": "abc123", \ "enabled": true, \ "roles": [ \ "ROLE_MONITORING" \ ], \ "noOfDaysRemainingForPwdExpiry": 0 \ }' 'https://uagname:9443/rest/v1/config/adminusers'

Expected Behavior

should have provided the invoke-restmethod response

Current Behavior

ConvertTo-IRM : Cannot process argument transformation on parameter 'CurlCommand'. Cannot convert value "curl -X PUT
--header " to type "CurlCommand". Error: "You cannot call a method on a null-valued expression."
At line:1 char:28

  • ConvertTo-IRM -CurlCommand 'curl -X PUT --header 'Content-Type: appli ...
  •                        ~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [ConvertTo-IRM], ParameterBindingArgumentTransformationException
    • FullyQualifiedErrorId : ParameterArgumentTransformationError,ConvertTo-IRM

Possible Solution

Steps to Reproduce (for bugs)

ConvertTo-IRM -CurlCommand 'curl -X PUT --header 'Content-Type: application/json' --header 'Acce
pt: application/json' -d '{ \ "name": "vRops", \ "password": "abc123", \ "enabled": true, \ "roles": [
\ "ROLE_MONITORING" \ ], \ "noOfDaysRemainingForPwdExpiry": 0 \ }' 'https://uagname:9443/rest/v1/config/adminusers
' --data ""' -String

> $PSVersionTable
Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      17134  858
> Get-Module Curl2PS

Great! Thanks for reporting that. I'll take a look and get that working.

Hey, where did this command come from? With the format of the body (-d) in that command, I don't believe that is a valid curl command. Here is how I would expect that same command to look (this works in the latest version which will be published momentarily):

curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" -d "{ \"name\": \"vRops\", \"password\": \"abc123\", \"enabled\": true, \"roles\": [ \"ROLE_MONITORING\"], \"noOfDaysRemainingForPwdExpiry\": 0 }" "https://uagname:9443/rest/v1/config/adminusers"

Noticed the use of double quotes and the escaped double quotes in the json body.

Here's another example from the Dropbox API that has a json body:

curl -X POST https://api.dropboxapi.com/2/account/set_profile_photo \
    --header "Authorization: Bearer <token>" \
    --header "Content-Type: application/json" \
    --data "{\"photo\": {\".tag\": \"base64_data\",\"base64_data\": \"SW1hZ2UgZGF0YSBpbiBiYXNlNjQtZW5jb2RlZCBieXRlcy4gTm90IGEgdmFsaWQgZXhhbXBsZS4=\"}}"

I'm guessing the \ in your example would represent linebreaks, but I haven't implemented detection for that yet.