curl command in linux - linux

How we can add JSON parameters in a curl command to fetch data ?
PS: I have tried to fetch data from some source using curl command but it requires passing JSON parameters in it. So how I will accomplish it ?

I think mentioning content type as json and passing data will do the things right
curl -H "Content-Type: application/json" -d '{"key1":"value1","key2":"value2"}' http://domain.com/rest/path/here
Above will work for GET Method, for POST method
curl -H "Content-Type: application/json" -X POST -d '{"key1":"value1","key2":"value2"}' http://domain.com/rest/path/here

Related

How do I interact with the hackage API using curl?

There are sparsely documented methods here. This page just mentions there's an API, and links to the hackage-security library which 5min poking around doesn't help me figure out how to form an http request to the (which?) server
The following just get me a stub html file:
$ curl -H "Accept: application/json" hackage.org/package/aeson/
$ curl -H "Accept: application/json" hackage.org/api/package/aeson/
old related: Does Hackage have an API?
You have the base URL wrong. It's https://hackage.haskell.org/.
curl -H 'Accept: application/json' https://hackage.haskell.org/package/aeson
yields the output
{"0.1.0.0":"normal","0.10.0.0":"deprecated","0.11.0.0":"normal","0.11.1.0":"normal","0.11.1.1":"normal","0.11.1.2":"normal","0.11.1.3":"normal","0.11.1.4":"normal","0.11.2.0":"normal","0.11.2.1":"normal","0.11.3.0":"normal","0.2.0.0":"normal","0.3.0.0":"normal","0.3.1.0":"normal","0.3.1.1":"normal","0.3.2.0":"normal","0.3.2.1":"normal","0.3.2.10":"normal","0.3.2.11":"normal","0.3.2.12":"normal","0.3.2.13":"normal","0.3.2.14":"normal","0.3.2.2":"normal","0.3.2.3":"normal","0.3.2.4":"normal","0.3.2.5":"normal","0.3.2.6":"normal","0.3.2.7":"normal","0.3.2.8":"normal","0.3.2.9":"normal","0.4.0.0":"normal","0.4.0.1":"normal","0.5.0.0":"normal","0.6.0.0":"normal","0.6.0.1":"normal","0.6.0.2":"normal","0.6.1.0":"normal","0.6.2.0":"normal","0.6.2.1":"normal","0.7.0.0":"deprecated","0.7.0.1":"deprecated","0.7.0.2":"deprecated","0.7.0.3":"deprecated","0.7.0.4":"normal","0.7.0.5":"deprecated","0.7.0.6":"normal","0.8.0.0":"deprecated","0.8.0.1":"deprecated","0.8.0.2":"normal","0.8.1.0":"normal","0.8.1.1":"normal","0.9.0.0":"normal","0.9.0.1":"normal","1.0.0.0":"normal","1.0.1.0":"normal","1.0.2.0":"normal","1.0.2.1":"normal","1.1.0.0":"normal","1.1.1.0":"normal","1.1.2.0":"normal","1.2.0.0":"normal","1.2.1.0":"normal","1.2.2.0":"normal","1.2.3.0":"normal","1.2.4.0":"normal","1.3.0.0":"normal","1.3.1.0":"normal","1.3.1.1":"normal","1.4.0.0":"normal","1.4.1.0":"normal","1.4.2.0":"normal","1.4.3.0":"normal","1.4.4.0":"normal","1.4.5.0":"normal","1.4.6.0":"normal","1.4.7.0":"normal","1.4.7.1":"normal","1.5.0.0":"normal","1.5.1.0":"normal","1.5.2.0":"normal","1.5.3.0":"normal","1.5.4.0":"normal","1.5.4.1":"normal","1.5.5.0":"normal","1.5.5.1":"normal","1.5.6.0":"normal","2.0.0.0":"normal","2.0.1.0":"normal","2.0.2.0":"normal","2.0.3.0":"normal"}

How can i send a base64 image to Azure Face-API with curl?

as my question mention it, how do i need to change this statement to send an image in base64 to Azure?
curl -H "Ocp-Apim-Subscription-Key: ***hidden***" "https://***hidden***.cognitiveservices.azure.com/face/v1.0/detect?detectionModel=detection_03&returnFaceId=true&returnFaceLandmarks=false"
-H "Content-Type: application/json" --data-ascii "{\"url\":\"https://upload.wikimedia.org/wikipedia/commons/c/c3/RH_Louise_Lillian_Gish.jpg\"}"
Thank you!
how do i need to change this statement to send an image in base64 to Azure?
As per this documentation, your curl command seems fine.
Alternatively, you can try as suggested by muru:
'{"image" : "'"$( base64 ~/Pictures/1.jpg)"'"}
Updated answer:
As per Use the Face client library:
curl -v -X POST "https://westus.api.cognitive.microsoft.com/face/v1.0/detect?returnFaceId=true&returnFaceLandmarks=false&returnFaceAttributes={string}&recognitionModel=recognition_04&returnRecognitionModel=false&detectionModel=detection_03&faceIdTimeToLive=86400" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: {subscription key}" --data-ascii "{\"url\":\"https://csdx.blob.core.windows.net/resources/Face/Images/identification1.jpg\"}"
You can refer to similar issues: can't send/request base64 to azure face api with python and Face API need support for base64 string or Local File URL or Native File URL instead of Image URL
curl -X POST "https://.cognitiveservices.azure.com/face/v1.0/detect" -H "Content-Type: application/octet-stream" -H "Ocp-Apim-Subscription-Key: 27e993*********6aaa2464" --data-binary #'/home/rafael/Downloads/person.jpg'
is the solution that works. As far as I can tell, the documentation seems outdated.

curl command with queryparameter for passing urlencode

I have been hitting a curl command with queryparametr in the request and passing a json format in the query parameter , but I am getting error like (" some well formatted json in parameter query.unexpected character encountered parsing error while parsing value .
curl -g --request GET -H "Content-Type:application/json" -H "apitoken:abcd" "https://odat.abc.com/api/data?query=$(echo '$jsonInput')"
jsonInput is the json format file we are passing here.
See https://stackoverflow.com/a/32980082/1395722
curl -G --request GET -H "Content-Type:application/json" -H "apitoken:abcd" "https://odat.abc.com/api/data" --data-urlencode "query=$(echo $jsonInput)"

Pagination for search - dockerhub API

I need to get all repositories with a provided name from DockerHub. I already tried various ways to get to next page of results received for the following call:
curl -k -H "Accept: application/json" -X GET https://index.docker.io/v1/search?q=sonarqube
Options which haven't worked:
curl -k -H "Accept: application/json" -X GET https://index.docker.io/v1/search?q=sonarqube&n=25&page=2
curl -k -H "Accept: application/json" -X GET https://index.docker.io/v1/search?q=sonarqube&page_size=25&page=2
Am I missing anything, or is there an alternative to get these results?
I simply used this link to navigate to the second page:
https://index.docker.io/v1/search?q=sonarqube&page=2
I works for page attibute range from 1 to num_pages which is returned in the JSON response. If you provided a number higher than num_pages it returns the last page.
Curl command as requested:
curl -k -H "Accept: application/json" -X GET "https://index.docker.io/v1/search?q=sonarqube&page=2"

How to POST URL in data of a curl request

I am trying to post two parameters using curl, path and fileName:
curl --request POST 'http://localhost/Service' --data "path='/xyz/pqr/test/'&fileName='1.doc'"
I know something is wrong in this.
I have to use something like URLEncode. I tried many things still no luck.
Please give an example how can I post the url in data of curl request.
Perhaps you don't have to include the single quotes:
curl --request POST 'http://localhost/Service' --data "path=/xyz/pqr/test/&fileName=1.doc"
Update: Reading curl's manual, you could actually separate both fields with two --data:
curl --request POST 'http://localhost/Service' --data "path=/xyz/pqr/test/" --data "fileName=1.doc"
You could also try --data-binary:
curl --request POST 'http://localhost/Service' --data-binary "path=/xyz/pqr/test/" --data-binary "fileName=1.doc"
And --data-urlencode:
curl --request POST 'http://localhost/Service' --data-urlencode "path=/xyz/pqr/test/" --data-urlencode "fileName=1.doc"
I don't think it's necessary to use semi-quotes around the variables, try:
curl -XPOST 'http://localhost/Service' -d "path=%2fxyz%2fpqr%2ftest%2f&fileName=1.doc"
%2f is the escape code for a /.
http://www.december.com/html/spec/esccodes.html
Also, do you need to specify a port? ( just checking :) )

Resources