1

I am using curl command in powershell in my Windows machine. I am trying to create an issue in JIRA which I have installed in my local. I tried following but it throws me error. Can someone let me know what am I missing and how to fix it?

PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data $parse.json -H    
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**

*curl: (6) Could not resolve host: Content-Type
HTTP/1.1 415 Unsupported Media Type

Server: Apache-Coyote/1.1
X-AREQUESTID: 770x749x1
X-ASEN: SEN-L8183526
Set-Cookie: JSESSIONID=D0B4391C94413FDDB1291C419F3E1360; Path=/; HttpOnly
X-Seraph-LoginReason: OK
Set-Cookie: atlassian.xsrf.token=B3EL-GHY4-P1TP-IMD0|d3d735e0a6566f8a97f99c96e80042551def3192|lin; Path=/
X-ASESSIONID: 1v4terf
X-AUSERNAME: raji
X-Content-Type-Options: nosniff
Content-Type: text/html;charset=UTF-8
Content-Length: 0
Date: Sun, 10 Jul 2016 07:20:36 GMT
*

When I try following I get this error:

PS C:\Users\raji> **curl -D- -u raji:raji -X POST --data @parse.json -H 
"Content-Type: application/json" http://localhost:8080/rest/api/2/issue**

*At line:1 char:38
+ curl -D- -u raji:raji -X POST --data @parse.json -H "Content-Type: ap ...
+                                      ~~~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@parse' can be used only as an argument to a command. To reference variables in an expression use '$parse'.
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : SplattingNotPermitted*

And hence I tried $ instaed of @ in file name.

"parse.json" File has following content:

{
    "fields": {
       "project":
       { 
          "key": "Demo"
       },
       "summary": "REST ye merry gentlemen",
       "description": "Creating of an issue using project keys and issue type names using the REST API",
       "issuetype": {
          "name": "Bug"
       }
   }
}

As this is windows machine, I also tried using slash (/) in parse.json file (saw in few posts that / will remove the error) but that also did not help. Please can someone let me know how to fix this?

R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
Raji
  • 857
  • 6
  • 18
  • 37
  • 1
    I also noticed that in error output following is mentioned: Content-Type: text/html;charset=UTF-8 Content-Length: 0 In curl command I have mentioned content type as: "Content-Type: application/json" – Raji Jul 10 '16 at 07:46

1 Answers1

1

In the first case

curl -D- -u raji:raji -X POST --data $parse.json -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue

$parse is interpreted by powershell as variable, $parse.json as attribute json of the variable $parse, which does not exist, so the command executed would be

curl -D- -u raji:raji -X POST --data -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue

data is -H, and the content type header is interpreted as url to access.

In the second case the @ in powershell is interpreted as splat operator, if you want a literal @ (which is interperted by curl and not by powershell), simply quote the string:

curl -D- -u raji:raji -X POST --data "@parse.json" -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue

Now it should use the contents of the file parse.json as data.

Community
  • 1
  • 1
mata
  • 67,110
  • 10
  • 163
  • 162
  • Thanks a ton Mata. Your explanation helped a lot to understand my error and fix provided by you also worked fine. I am able to create issue in JIRA. curl -D- -u raji:raji -X POST --data "@parse.json" -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue – Raji Jul 10 '16 at 10:11