I am using Marklogic 9 and try to ingest data from external source into MarkLogic. I made an REST API on port 8031. When I try to execute the following curl command:
curl --anyauth --user admin:admin -i -X POST -d https://services7.arcgis.com/21GdwfcLrnTpiju8/arcgis/rest/services/Geluidsbelasting/FeatureServer/0/query?where=1%3D1&outFields=*&outSR=4326&f=json
-H "Content-type: application/json" -H "Accept: application/json" \
'http://localhost:8031
After executing this statement I receive the error:
Curl: URL is not specified
Can you please help me out!
Many thanks
Erik
Your -d parameter has special characters that are not escaped. Try putting quotes around your -d url. It will prevent your command from getting truncated and misinterpreted at & signs..
HTH!
I am trying to follow the documentation from timekit.io. I am attempting to do something as simple as send a curl request to do basic authentication as seen in this section of the docs. I have replaced the Timekit-App:name-of-app with the name of my app which I found in the app-settings of my timekit account. I also replaced the email & password with the one's I use to login into my account.
I simply copied and pasted the curl command as is into my terminal and I get a response that says {"error":"Content-type should be json!"} I am not sure if I am not supposed to copy and paste it as is, or what I may be doing wrong, but my understanding is I am supposed to get a json response with a email and a api token among some other data.
Here is my curl command.
curl -X POST \
-H 'Timekit-App: jl-fit' \
-d '{
"email": "email#email.com",
"password": "password"
}' \
https://api.timekit.io/v2/auth
Looks like you have discovered a bug in their docs/examples.
The API you're connecting to expects JSON content type, but curl by default (for POSTing data) uses application/x-www-form-urlencoded. You can fix it by adding the header field explicitly with: -H 'Content-Type: application/json'.
Also, when you use the -d/--data option, method defaults to POST, so it doesn't have to be specified explicitly.
All put together, this should work:
curl \
-H 'Content-Type: application/json' \
-H 'Timekit-App: jl-fit' \
-d '{"email": "email#email.com", "password": "password"}' \
"https://api.timekit.io/v2/auth"
When having multiple arguments, it can be convenient to keep them in an array (no need to escape newlines). For example:
args=(
-H 'Content-Type: application/json'
-H 'Timekit-App: jl-fit'
-d '{"email": "email#email.com", "password": "password"}'
"https://api.timekit.io/v2/auth"
)
curl "${args[#]}"
In curl help I see (for example) :
-d, --data DATA HTTP POST data (H)
What does the --data mean ? Does it mean I can use -d or --data ?
I am attempting to create a hook using the create hook api found on
http://developer.github.com/v3/repos/hooks/#create-a-hook
but I am getting a 301 when I attempt to post, so I am sure I am doing it wrong...
A couple of questions...
1) How does github know that I can create a hook for that repo if it is private? I am sure I need to authenticate with the POST, but how?
2) Is the following curl statement a valid example of how to create a hook?
curl -v -H "Content-Type: application/json" -X POST -d "{ "name": "cia",
"active": true, "events": [ "push" ], "config": {
"url": "http://requestb.in/######", "content_type": "json" } }"
http://github.com/repos/#####/#####/hooks
I have replaced certain elements with ##### for security sake...
3) If the above is incorrect, may I please have a snippet of a valid example to create a hook for the webhook named "cia"?
curl -usigmavirus24 -v -H "Content-Type: application/json" -X POST -d '{"name": "cia", "active": true, "events": ["push"], "config": {"url": "...", "content_type": "json"}}' https://api.github.com/repos/sigmavirus24/reponame/hooks
Is the correct curl command. The URL you're posting to has to be https://api.github.com/:endpoint where :endpoint in this case is repos/username/reponame/hooks. You also need to use 's around the JSON body for the curl command because otherwise you'll get strings like "{ " concatenated with the output of commands like name, cia, active, events, etc.
Also the -u :username option is necessary for curl so it will tell curl that it MUST authenticate and ask you for the password to do so.
If you don't mind your password being in your bash history (WHICH YOU SHOULD) you can also do -u username:password. Or even better you can base64 encode your credentials in the form username:password and then send that as a header like so: Authentication: Basic <base64-encoded-credentials.
I am trying to do a simple PUT request using CURL. Simple it is on a terminal but not able to get it working within my Groovy script.
Here is a snippet of it :-
class Test {
//Throws 415 Cannot Consume Content Type
void testPUT () {
println "curl -i -X PUT -H \"Content-Type: application/json\" -d '{\"Key1\":1, \"Key2\":\"Value2\"}' http://<hostname>/foo/".execute().text
}
// Works Perfectly Fine
void testGET () {
println "curl -i -X GET -H \"Content-Type: application/json\" http://<hostname>/foo".execute().text
}
}
I also tried to enclose the command using triple quotes like:-
"""curl -i -X PUT -H "Content-Type:application/json" -d '{"Key1":1,"Key2":"Value2"}' http://<hostname>/foo""".execute().text
All my attempts just gives 415 Content Type Cannot be Consumed
When I simply use the curl command on a terminal window, both PUT and GET methods work fine.
Am I missing something? Any help would be appreciated!
Thank You!
Try using the list variation of the string and see if that works:
println ["curl", "-i", "-X PUT", "-H 'Content-Type:application/json'", "-d '{\"Key1\":1, \"Key2\":\"Value2\"}'", "http://<hostname>/foo/"].execute().text
I was having a similar problem and this was the only way I could find to solve it. Groovy will split the string into arguments at each space and I suspect this was tripping up Curl and the -H argument pair. By putting the string into the list variant, it keeps each item together as an argument.
Building on Bruce's answer, you will also need to tokenize "-X PUT". Tested out on groovy 2.3.6. ["curl", "-H", "Content-Type: application/json", "-H", "Accept: application/json", "-X", "PUT", "-d", data, uri].execute()
This works in my terminal
groovy -e "println 'curl -i -H \'Content-Type:application/json\' -XPUT -d \'{\"test\":4}\' http://google.fr/'.execute().text"
If it does not work for you, then this is likely not a groovy problem.
Thanks xynthy for the list variation hint, I was still seeing the dreaded
"Content type 'application/x-www-form-urlencoded' not supported"
with your example, but breaking up the -H and the content type strings worked.
This is confirmed working in groovy 1.8:
["curl", "-H", "Content-Type: application/json", "-H", "Accept: application/json", "-X PUT", "-d", data, uri].execute().text
First I installed the groovy post build plugin
https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin
Then I have included groovy post build plugin in my post build configuration of my jenkins job
and used the command
"curl --request POST http://172.16.100.101:1337/jenkins/build".execute().text
Here my endpoint is http:172.16.100.101:1337/jenkins/build