HTTP post request?param=PARAM vs --data-urlencode - linux

i am just querying my InfluxDB and i made it work, but i never did web so i am not so experienced with http protocol. I need to do curl request.
This one works fine:
curl -X POST http://localhost:8086/api/v2/query?orgID=12345678 --header "Authorization: Token MYTOKEN" --header "Content-Type: application/vnd.flux" --data-binary 'from(bucket:"MYBUCKET") |> range(start: -55m) |> yield()'
But this does not and i dont understand why, i thought it is the same thing just differently put.
curl -X POST http://localhost:8086/api/v2/query --data-urlencode "orgID=12345678" --header "Authorization: Token MYTOKEN" --header "Content-Type: application/vnd.flux" --data-binary 'from(bucket:"MYBUCKET") |> range(start: -55m) |> yield()'
I guess no need for u to understand Influx to help me, I post this question after an hour of research and I just dont have time for this right now, can someone please just explain the concept to me? I can make it work obviously but this frustrates me since i thought its the same thing.
Thanks four the time, Q.

The mistake - is that you sends two payloads. The first example contains orgId as url parameter. In second orgId sent like payload and also sent data with influx query.
curl -X POST http://localhost:8086/api/v2/query
--data-urlencode "orgID=12345678" <-- FIRST PAYLOAD
--header "Authorization: Token MYTOKEN" --header "Content-Type: application/vnd.flux"
--data-binary 'from(bucket:"MYBUCKET") |> range(start: -55m) |> yield()' <-- SECOND PAYLOAD
And when you send such a request, it just takes the last payload

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"}

Calling API through requests Library to get access token

I am trying to get the access token for a specific API, the curl command is given below:
curl --location --request POST 'https://example.com/oauth/connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=abcd' \
--data-urlencode 'client_secret=abc' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'username=us' \
--data-urlencode 'scope=a' \
--data-urlencode 'password=abc'
I have the following code in python:
url = 'https://example.com/oauth/connect/token'
body = {'client_id':'abcd',
'client_password':'abc',
'grant_type':'password',
'username':'us',
'scope':'a',
'password':'abc'}
headers = {'Content-Type':'application/x-www-form-urlencoded'}
response = requests.post(url, data=body, headers=headers, verify=False)
print(response,response.content)
I keep receiving a <Response [400]> b'{"error":"invalid_client"}' error.
I believe I have tried almost everything there is out there and I am lost. Please let me know if I am missing something really simple.
I noticed, that your curl command uses client_secret, while your requests command uses client_password.
For debugging such requests, I recommend free pages like https://www.toptal.com/developers/postbin/, where you can send the curl and the requests message and compare what arrived on the endpoint.

How to use azure translator with authorization token?

I want to use azure translator service with the Authorization token. There are plenty of resources explaining how to do it with subscription key but I could not found any resource explaining the use of authorization token. I can get the authorization token but when I send a request with it, the response status code is 401.
This is how I send the request:
curl POST 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=es' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer token' \
--data-raw '[{'\''Text'\'':'\''Hello World!'\''}]'
If you want to call Text Translation API with authentication token, please refer to the following steps
Get a token. If your service is global, the endpoint is https://api.cognitive.microsoft.com/sts/v1.0/issueToken
curl -v -X POST \
"https://YOUR-REGION.api.cognitive.microsoft.com/sts/v1.0/issueToken" \
-H "Content-type: application/x-www-form-urlencoded" \
-H "Content-length: 0" \
-H "Ocp-Apim-Subscription-Key: YOUR_SUBSCRIPTION_KEY"
Besides, please note that an authentication token is valid for 10 minutes. The token should be reused when making multiple calls to the Translator. However, if your program makes requests to the Translator over an extended period of time, then your program must request a new access token at regular intervals (for example, every 8 minutes).
Call API
curl -X POST 'https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=de' \
-H 'Authorization: Bearer YOUR_AUTH_TOKEN' \
-H 'Content-Type: application/json' \
--data-raw '[{ "text": "How much for the cup of coffee?" }]' | json_pp
For more details, please refer to here and here.

Not receiving push notification with encrypted payload

I've been following the document over in this resource to get Push-Notifications sending to a browser with a payload. (Chrome 53.0.2785.116 m).
I'm using the Nodejs Crypto library to generate the keys and they all pass the verification test created by the folks at Google.
I can send and receive a Push-Notification when I do not include the encrypted payload. As soon as I attach the 'raw_data' tag with the encrypted payload the browser no longer receives the Push-Notification (although Curl still comes back with a 'success(1)' response)
Below is the Curl message with and without the payload.
Without Payload -
curl --header "TTL:86400"
--header "Authorization: key=API_KEY"
--header "Encryption: salt=E2oUmcFWbb41wk5DuTbuoA"
--header "Crypto-Key: dh=SERVER_PUBLIC_KEY"
--header "Content-Encoding: aesgcm"
--header "Content-Type: application/json"
https://android.googleapis.com/gcm/send -d
"{\"registration_ids\":[\"CLIENT_KEY\"],\"content_available\":true}"
--insecure
With Payload -
curl --header "TTL:86400"
--header "Authorization: key=API_KEY"
--header "Encryption: salt=E2oUmcFWbb41wk5DuTbuoA"
--header "Crypto-Key: dh=SERVER_PUBLIC_KEY"
--header "Content-Encoding: aesgcm"
--header "Content-Type: application/json"
https://android.googleapis.com/gcm/send -d
"{\"registration_ids\":[\"CLIENT_KEY\"],\"raw_data\":\"UnGSxqxfy9yDwPgCVeXJibQyPX8Hz28\",\"content_available\":true}"
--insecure
Both return a success message
{"multicast_id":9197002368280649941,
"success":1,"failure":0,
"canonical_ids":0,
"results":[{"message_id":"0:1474618927798802%bc86b90cf9fd7ecd"}]}
but the latter is not received by the browser.
We're now into the fourth day of head scratching. Any help would be great.

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