26

I found "Query using POST" from here.

And tried to use curl command from command like. Installed curl by refering this for windows.

Here is my CURL string:

curl -D- -u admin:password -X POST -H "Content-Type: application/json" --data 
'{"jql":"project = CI","startAt":0,"maxResults":50,"fields":["summary","status","assignee"]}' 
"https://myclientname.atlassian.net/rest/api/2/search"

This is how I'm doing and getting error:

{"errorMessages":["Unexpected character (''' (code 39)): expected a valid value
(number, String, array, object, 'true', 'false' or 'null')\n
at [Source: org.apache.catalina.connector.CoyoteInputStream@1626cb2; line: 1, column: 2]"]}

Is there any problem making this curl string in windows? Please suggest? How can I correct this and get JSON object? Please note that, userID, password and client name is correct. Thanks.

Marcos Dimitrio
  • 6,651
  • 5
  • 38
  • 62
AskMe
  • 2,495
  • 8
  • 49
  • 102
  • I just changed like this : curl -D- -u admin:password -X POST -H """Content-Type: application/json""" --data "{"""jql""":"""project = CI""","""startAt""":0,"""maxResults""":50,"""fields""":["""id""","""key"""]}" """https://myclientname.atlassian.net/rest/api/2/search""" Its saying: curl: (6) Could not resolve host: = curl: (3) [globbing] bad range specification in column 43 curl: (1) Protocol ""https" not supported or disabled in libcurl – AskMe Jul 19 '15 at 17:41
  • Based on your comment, and just as an experiment to get more information about the problem, try again without using HTTPS. In other words, use `"http://myclientname.atlassian.net/rest/api/2/search"` instead of `"https://myclientname.atlassian.net/rest/api/2/search"`. – Shaun Luttin Jul 19 '15 at 23:11
  • Did you get any luck on this? I got the same issue. – Lee Jan 19 '16 at 23:22

5 Answers5

41

Seems to be an windows issue. Do not use the ' (single-quote) character.

Instead, use " (double-quote) character for enclosing the string. Then, if you have inner quotes, use """ (3x double-quotes) to escape them.

Example: "{ """name""":"""Frodo""", """age""":123 }"

Peter Kennedy
  • 541
  • 6
  • 11
2

I tried the cURL you pointed to in your question, but with no luck. Also, the cURL comes with Git is not working either. However, the one I installed with CygWin works. And the same command is also working in Ubuntu. Which basically indicates that your command itself is OK.

If you are working on Windows, I recommend you to use a tool called Fiddler. It can perform almost all HTTP requests you may need. Good luck!

Update: Here I add the steps to make HTTP POST request with Fiddler.

1) After starting Fiddler, you will see the GUI like Figure 1. The upper right panel is where you should input staff like JIRA's website, request type, and the content you want to post. To be specific, under the "Composer" tab, you need to select "POST" as your request type, and put the JIRA's URL there, keep HTTP/1.1 selected. You should put the request header under the URL bar. Now, you need to pay attention to. At least, you should input two things in HTTP header: the content type, which is "application/json", and the authorization header. The authentication is a Base64 string, you can get your Base64 string here with your "admin:password". If you want to know more about the basic authentication method, please refer Jira's website here. The lower right panel of the GUI is where you should put your post content. enter image description here

2) When you get these staff ready, you can click the "Execute" button at upper right corner of the GUI. The execution result will be shown at the left panel. As Figure 2 shows, if you get a result with the status 200, congratulations, you got it. If you get other types of results, please google the error code or leave comments here. enter image description here

3) Double click the result, the returned JSON content will be shown in the lower right panel like Figure 3. You can try different tab to see the returned staff. For example, if you go to the "TextView", you will get the returned JSON as pure string. enter image description here

Please comment if you have any further question.

Chong Tang
  • 2,066
  • 15
  • 12
  • I'm very new to this Fiddler. Any step by step guide , how to use this in this case? – AskMe Jul 20 '15 at 04:38
  • Hi, here is a post that shows you how to use Fiddler with pictures. http://www.asjava.com/tools/fiddler-tutorial-how-to-use-fiddler/. Fiddler is very good, my team and I use it everyday. Hope it helps. – Chong Tang Jul 20 '15 at 04:45
  • What is the steps to make this curl request using Fiddler? Please edit your answer with the steps. – AskMe Jul 20 '15 at 04:54
1

This worked for me:

curl.exe -u elastic:Password! -k -X POST "https://localhost:9200/_security/user/kibana_system/_password?pretty" -H "Content-Type: application/json" --data '{"""password""" : """CHANGEME"""}'

Notice the format of the last parameter (--data): it uses single quotes (') as string delimiters and triple double-quotes (") inside)

Starnuto di topo
  • 3,215
  • 5
  • 32
  • 66
0

Pls verify if you have any value wrapped with single quote.

e.g

"NetworkType": 'Test'
Ishan Liyanage
  • 2,237
  • 1
  • 26
  • 25
0

Try this. It should work.

curl -D- -u admin:password -X POST -H "Content-Type: application/json" --data 
\\"{"jql":"project = CI","startAt":0,"maxResults":50,"fields":["summary","status","assignee"]}\\"
"https://myclientname.atlassian.net/rest/api/2/search"

Don't forget to use a slash (\*{}\*}after and before json

Lemon
  • 1,184
  • 11
  • 33