0

When ever I run the curl command it's throwing a syntax error. I've followed this documentation to list all artifacts in 'war-release' repo. No idea what's the issue.

$curl -u uname:password -X POST https://<artifactory.com>/artifactory/api/search/aql -d items.find({"repo":"war-release"})

-bash: syntax error near unexpected token `('

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
user6136315
  • 695
  • 4
  • 13
  • 37

3 Answers3

6

Another option that doesn't requires to enclose the query with " or ' and works in most environments is to save the query to file, lets call it aql.query

items.find(
     {
          "repo":"war-release"
     }
)

and then run the following curl command from the same directory that contains the aql.query file (don't forget to replace the templates in the command with your user name, password, host and port).

curl -X POST -uuser:password 'http://host:port/artifactory/api/search/aql' -Taql.query

Gidi.S
  • 171
  • 6
2

Try this curl statement:

curl -u uname:password -X POST -d "items.find({"repo":"war-release"})" https:///artifactory/api/search/aql

johnnywhoop
  • 964
  • 2
  • 7
  • 28
  • our server accepting only secure connections, so I appended command with "--insecure -v". It's not writing any thing throwing a 404. It supposed to be run AQL command. $curl -u uname:password -X POST -d "items.find({"repo":"war-release"})" --insecure -v https://artifactory.com/api/search/aql 404 Not Found

    Not Found

    The requested URL /api/search/aql was not found on this server.


    – user6136315 Mar 30 '16 at 19:19
  • Im not sure what you are trying to do but --insecure doesnt bypass ssl. It just skips certificate validation. See http://stackoverflow.com/questions/8520147/curl-insecure-option. It sounds like "war-release" couldnt be found so you are getting a 404. – johnnywhoop Mar 30 '16 at 19:26
  • The error you're getting as a response is not one that's returned by Artifactory - are you behind a reverse proxy? – danf Mar 30 '16 at 20:06
  • yes i'm behind the reverse proxy. I'm able to see the repos. mysql> select distinct(repo) from nodes; war | | war-dev | | war-release Listed so many repos...... And tried this $curl --capath /etc/pki/tls/certs -u uname:password -X POST https://artifactory.com/artifactory/api/search/aql -d "items.find({"repo":"war-dev"})" Still it's throwing the same error. – user6136315 Mar 30 '16 at 20:37
  • The original error you posted is thrown by bash... did you try enclosing the query with " or ' ? – danf Mar 30 '16 at 21:03
  • yes. Now I'm getting below error. $ curl -u uname:password -X POST https://artifactory.com/artifactory/api/search/aql -d "items.find({"repo":"war-release"})" { "errors" : [ { "status" : 400, "message" : "Bad Request" } ] – user6136315 Mar 30 '16 at 21:09
  • Maybe mark this as answered and ask another question since the purpose of the comments is to clarify not to ask more questions. You will get more visibility that way, and a quicker answer. – johnnywhoop Mar 30 '16 at 21:40
2
curl -X POST -k -u user:pwd 'https://xxx/artifactory/api/search/aql' -d 'items.find({"repo":"repo-local"})' gives json output.

use single quotes -- This worked for me fine

slfan
  • 8,950
  • 115
  • 65
  • 78
Springhills
  • 360
  • 1
  • 5
  • 12