Powershell Double Quotation Marks

I am trying to invoke the curl command in powershell and pass some JSON information.

Here is my command:

curl -X POST -u username:password -H "Content-Type: application/json" -d "{ "fields": { "project": { "key": "key" }, "summary": "summary", "description": "description - here", "type": { "name": "Task" }}}" 

I had smoothing errors and "inconsistent brackets", and the host could not be resolved, etc.

Then I tried the double quote prefix in the line with the return line character, but could not recognize the character - in the json description field

thanks

EDIT 1:

When I wrote the curl command in a regular batch file, I used double quotes and no single quotes. Also, on the -d line, I avoided all double quotes with \ , and the command worked.

In this case, my curl actually points to curl.exe. I indicated the path, just did not list it here. I also tried adding single quotes around -d , and I got:

 curl: option -: is unknown curl: try 'curl --help' or 'curl --manual' for more information 

It looks like it can't recognize the character - in JSON

+5
source share
1 answer

Put the data in curl.exe, instead of trying to avoid it.

 $data = @{ fields = @{ project = @{ key = "key" } summary = "summary" description = "description - here" type = @{ name = "Task" } } } $data | ConvertTo-Json -Compress | curl.exe -X POST -u username:password -H "Content-Type: application/json" -d "@-" 

curl.exe reads stdin if you use @- as a data parameter.

PS: I highly recommend that you use the correct data structure and ConvertTo-Json as shown, rather than manually creating a JSON string.

+8
source

Source: https://habr.com/ru/post/1235219/


All Articles