2

I need to automate the issues insertion in Jira, so I need to use a REST API, I run the curl from the command line, here is my command

C:\WINDOWS\system32>curl.exe -D- -u fred:fred -X POST --data { "fields": {"project": { "key"="ZZZ-180" }, "summary": "REST TESTING" , "description": "Creation of a testing issue" , "issuretype" { "name": "Bug"}}} -H "Content-Type: application/json" http://ABCD.com:XXXX/rest/api/2/issue/

and here is what I receive:

curl: (6) Could not resolve host: fields
curl: (3) [globbing] unmatched brace at pos 10
curl: (3) [globbing] unmatched brace at pos 2
curl: (6) Could not resolve host: key=
curl: (6) Could not resolve host: ZZZ-180
curl: (3) [globbing] unmatched close brace/bracket at pos 1
curl: (6) Could not resolve host: summary
curl: (6) Could not resolve host: REST TESTING
curl: (6) Could not resolve host: ,
curl: (6) Could not resolve host: description
curl: (6) Could not resolve host: Creating of a testing issue
curl: (6) Could not resolve host: ,
curl: (6) Could not resolve host: issuretype
curl: (3) [globbing] unmatched brace at pos 2
curl: (6) Could not resolve host: name
curl: (3) [globbing] unmatched close brace/bracket at pos 4

Can anyone help me let the cURL define the JSON code written in data?

4
  • You have to quote the parameter, otherwise curl will use { as data and interpret the other parts as parameters (unknown)... Commented Jun 26, 2013 at 13:12
  • I tried but still the same error Commented Jun 26, 2013 at 13:14
  • also remove the white spaces {"fields":{ Commented Nov 29, 2013 at 13:07
  • @Blundell. My case was the spaces on the string. So unusual to my understanding. Thank you. Commented Jul 25, 2015 at 1:48

2 Answers 2

3

You would have to quote the string, but simplest way is putting JSON data in a file and asking cURL to read from it:

C:\WINDOWS\system32>curl.exe -D- -u fred:fred -X POST --data @data_to_send.json -H "Content-Type: application/json" http://ABCD.com:XXXX/rest/api/2/issue/

Note the @ before file name.

Sign up to request clarification or add additional context in comments.

6 Comments

I tried it but still JSON code is totally undefined.. How to identify JSON in curl,,, I never used JSON before so Sorry for my lack of knowledge abt how to install JSON to be used in cURL
You do not have to install JSON, JSON is a file format ;) cURL will simply transfer the content of data_to_send.json: put the JSON string in it and navigate to the folder or give full path (like --data C:\path\to\data_to_send.json).
Thanks so much,,, The problem now is in the authorization to the REST API! thanks anyways
I was trying to write this command in perl script to be passed to the command prompt... I used backtracks `` but it was always giving an error for the @ notation before the JSON file path... any suggestions?
how do you quote the string?
|
0

Your --data should look something like:

"{ \"fields\": {\"project\": { \"key\"=\"ZZZ-180\" }, \"summary\": \"REST TESTING\" , \"description\": \"Creation of a testing issue\" , \"issuretype\" { \"name\": \"Bug\"}}}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.