Post datas from distant file - file

I know how to post data from a local file with curl :
curl -i -X POST -H 'Content-Type: text/plain' -d #foo.txt http://bar.com/foobar
But I would like to do the same, but from a distant file, for example :
curl -i -X POST -H 'Content-Type: text/plain' -d #http://www.google.fr/robots.txt http://bar.com/foobar
If I try this command, I have warnings : Couldn't read data from file, this makes an empty POST.
Is is possible to do that?

I suppose that my answer is not new for you, but why you can't do this:
curl http://www.google.fr/robots.txt > /tmp/foo.txt
curl -i -X POST -H 'Content-Type: text/plain' -d #/tmp/foo.txt http://bar.com/foobar

Related

cURL command returns HTTPError 415

I am trying to use the curl command from a batch script.
curl -k -o "C:\Temp\**8.txt" -X POST -H "auth-key: 1****G-*****" -H "Content-Type:application/json" --data-binary #"***\test.txt" https://localhost:9443/security/backend-connectivity
I am seeing an error:
HTTPError: (415, 'Expected an entity of content type application/json, text/javascript')
My JSON file is good.
Any input would be appreciated.

How to encode a query in CURL Command Line when passing a query as a sql parameter

I am trying to query via CURL command line but I believe I need to encode it.
Example:
curl -X GET -H "Authorization:c02c66a4531a43c5a0971d16c2823e1a" 'http://127.0.0.1:8050/api/core/query?sql=select n return n limit 10' -i
I don't ever see why this is a good idea, but here is a curl with an encoded match(n) return n limit 10' -i:
curl -X GET \
http://127.0.0.1:8085/api/core/query \
-H 'Authorization: c02c66a4531a43c5a0971d16c2823e1a' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'sql=match(n)%20return%20n%20limit%2010'\''%20-i'

Attach an image file to a BigCommerce Product

The BigCommerce API documentation suggests that image files can be uploaded through the API, without having to upload it elsewhere first:
POST /catalog/products/{product_id}/images
Creates an image on a product. Publically accessible URLs and files (form post) are valid parameters
Emphasis mine. My attempts, variations on the below, mostly come back with 422 image_url must be present if uploading by url.
curl -X POST \
https://api.bigcommerce.com/stores/redacted/v3/catalog/products/123/images \
-H 'accept: application/json' \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-H 'x-auth-client: redacted' \
-H 'x-auth-token: redacted' \
-F productImage=#img_123.jpg \
-F image_url=image_123.jpg
What does a correctly formed request look like, that POSTs an image file to a product?
Related:
Bigcommerce Python API, how do I create a product with an image?
A correctly formed request looks like this:
curl -X POST \
https://api.bigcommerce.com/stores/js......7j/v3/catalog/products/32011/images \
-H 'accept: application/json' \
-H 'cache-control: no-cache' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-H 'x-auth-client: ts2.........................r0r' \
-H 'x-auth-token: ihq.........................5b2' \
-F 'image_file=#Downloads/img_2405.jpg'
However, certain images can cause the misleading error; such as this one.
It's not clear what property of the file causes the error, but compressing or otherwise re-saving the image resolves the problem.

Unable to send JSON data to webserver using curl

I am trying to sent a curl command to a webserver to control a device in my home. The webserver contains the following JSON data:
{"result":1, "error":null, "id":0, "data":{"vid":2, "did":4, "device_type":"airconditioner", "default_name":"Air Conditioner Settings", "tags":"aircon", "is_sensor":1, "is_actuator":1, "is_silent":0, "has_time_series":0, "has_subdevice_count":0, "has_state":0, "gid":"0", "guid":"xxxx", "node":"yyy", "meta":{}, "shortName":"", "subDevices":{}, "last_data":{"DA":{"amOn":false, "tempTarget":22, "mode":1, "fanSpeed":0, "enabledZones":[1,1,0,0,0,0,0,0]}, "timestamp":1500523622862}}
Using curl I can send the following PUT command to turn the device on:
curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X PUT -d '{"DA":{"amOn":"true"}}' https://actron.ninja.is/rest/v0/device/xxxx?user_access_token=zzzz
However I am stuck in sending a PUT command to change the numbers in the enabledZones array.
I have tried many variations of the command below with no success:
curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X PUT -d '{"DA":{"enabledZones[1]":"0"}}' https://actron.ninja.is/rest/v0/device/xxxx?user_access_token=zzzz
Any suggestions will be very much appreciated
I think you are sending incorrect array request in json. To update array element 1 with 0, you need to use "enabledZones":[1,0,0,0,0,0,0,0].
Please see if below CURL command works
curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X PUT -d '{"DA":{"enabledZones":[1,0,0,0,0,0,0,0]}}' https://actron.ninja.is/rest/v0/device/xxxx?user_access_token=zzzz

Chinese text incorrectly identified as Portuguese

When I pass a snippet of Chinese text to the IBM Watson language detection method, the text is incorrectly identified as pt -- Portuguese:
curl -X POST -d "outputMode=json" \
"https://gateway.watsonplatform.net/language-translation/api/v2/identify" \
--data-urlencode "text=中国的工厂" \
--header "content-type: text/plain" \
--user "MY_USERNAME:MY_PASSWORD"
Am I encoding the text wrong, or doing something else wrong?
Or are IBM Watson's language identification models not useful in some cases, with Portuguese being returned as some kind of default?
You are referring to the old deprecated service. I am actually surprised that you got any result. The API for the current service record that you should be using is documented here - https://www.ibm.com/watson/developercloud/language-translator/api/v2/?curl#identify
The sample curl command is:
curl -u "{username}":"{password}" \
-H "content-type: text/plain" \
-H "accept: application/json" \
-X POST \
-d "this is a test" \
"https://gateway.watsonplatform.net/language-translator/api/v2/identify"

Resources