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"
Related
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'
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.
I have a device Stiebel Eltron heat pump home and I would like to use Linux shell curl (not php) curl to login (POST) and retrieve (GET) data once logged
Here is how my curl login POST call looks like (I used Firebug + persist option to copy/paste the below):
curl --data-urlencode 'userName=tutu&password=xx' \
'https://thesite/api/login?noCacheDummyValue=1459356436185' -X POST \
-H 'Host: thesite' \
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: en-US,en;q=0.7,fr-FR;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'Content-Type: application/json;charset=utf-8' \
-H 'Referer: https://thesite/mobile/app/app.html' \
-H 'Content-Length: 44' \
-H 'Cookie: JSESSIONID=qhs02mfeip2p1n5n4t2rj1huu'
But this gives me nothing in the output:
sh myproj.sh
curl: (52) Empty reply from server
Q1: What should I collect from this first POST, and how to do it?
I tried to get the cookie with --cookie-jar cookie.txt but nothing showed up in my current directory. However I sent cookies with the header... shouldn't I get them back?
After that I would like to continue the session I (think I) opened so to collect data from a GET that is (same method as above):
curl 'https://thesite/api/data/1036493/heatEnergy/today?noCacheDummyValue=1459356438440' \
-H 'Host: thesite' \
-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Accept-Language: en-US,en;q=0.7,fr-FR;q=0.3' \
-H 'Accept-Encoding: gzip, deflate, br' \
-H 'X-Requested-With: XMLHttpRequest' \
-H 'Referer: https://thesite/mobile/dashboard/dash.html' \
-H 'Cookie: JSESSIONID=qhs02mfeip2p1n5n4t2rj1huu'
Q2: How do I keep the session opened to perform the GETabove?
I tried --next option idea from here to call the GET after the POST; without success, --next option is not recognized on my Ubuntu Linux.
If it can help understanding, the page I should get is full of javascript (angularjs I think).
From your POST call it is obvious that you are trying to do an ajax XMLHttpRequest. Likely this is expecting json encoded data. However you are providing url-encoded data.
Probably you should try using something along
... -X POST -H "Content-Type: application/json" -d '{"userName":"tutu","password":"xx"}' 'https://thesite/api/login?noCacheDummyValue=1459356436185'
To make the login work, you need to match the way the server is maintaining the session. If session info is referred to via a cookie yo may just extract the cookie from the POST call (as you said you tried already, but on an error related response)
If the server does not use a straight way of referencing the session you might not succeed in getting your GET call working. If you are lucky maybe you then just need to parse a string from the page (fragment) or json data returned.
So monitor what a working handshake (e.g using a browser) is exchanging over the wire. And try identifing the important pieces of data. Then, put those together to form your GET call.
Thanks to rpy, I was able to do what I wanted:
Collect the session cookie:
curl -a -X POST -d '{"userName":"tutu","password":"xx"}' \
--trace-ascii debugdump.txt --cookie-jar cookies.txt \
-H 'Content-Type: application/json;charset=utf-8' \
-H 'Referer: https://thesite/mobile/app/app.html' \
'https://thesite/api/login?noCacheDummyValue=1459356436185' -o my.post
todo: check result is "ok" in my.post
todo: get content of cookies.txt into ${COOKIE}
Use it to retrieve the raw data I wanted:
curl -a \
-H 'Referer: https://thesite/mobile/dashboard/dash.html' \
-H 'Cookie:JSESSIONID='${COOKIE} \
'https://thesite/api/data/1036493/outTemp/lastMonth?noCacheDummyValue=1459972646687' \
-o lm_outTemp.get \
-L 'https://thesite/api/data/1036493/heatEnergy/lastMonth?noCacheDummyValue=1459972646694' \
-o lm_heatEnergy.get
And I already started working on how to process the data here: Firefox - Collecting the data used by LAB.min.js
I want this cURL
curl https://api.cardinity.com/v1/payments\
-H "Content-Type: application/json" \
-H 'Authorization: OAuth oauth_consumer_key="<your_consumer_key>", \
oauth_signature_method="HMAC-SHA1", \
oauth_timestamp="<timestamp>", \
oauth_nonce="<unique_random_string>", \
oauth_version="1.0", \
oauth_signature="<computed_oauth_signature>"'
transformed into Angular, I've tried everything.
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