I'm running my local emulator suite and I'm constantly getting error messages for my curl requests. The following command:
curl -X POST http://localhost:5001/my-project/us-central1/myFunction \
-H "Content-Type: application/json" \
-d '{"productId": 123456, "quantity": 100}'
Is always showing this in the emulator CLI:
> {"productId":123456,"quantity":100,"severity":"WARNING","message":"Request body is missing data."}
> {"severity":"ERROR","message":"Invalid request, unable to process."}
None of the code was executed in the function as it starts with a console log which is never printed here. Any thoughts?
That error occurs when you use the onCall method. So, I would assume that you are using functions.https.onCall. As explained in this documentation:
It's important to keep in mind that HTTPS callable functions are similar but not identical to HTTP functions. To use HTTPS callable functions you must use the client SDK for your platform together with the functions.https backend API (or implement the protocol).
If you want to directly call the function via its endpoint then you should follow the protocol specification for https.onCall. One of its requirements is the request body should be a JSON object with data as its main key.
An example request JSON object should be like this instead:
{
"data": {
"productId": 123456,
"quantity": 100
}
}
For reference, here's the full curl request:
curl -X POST http://localhost:5001/my-project/us-central1/myFunction \
-H "Content-Type: application/json" \
-d '{ "data": { "productId": 123456, "quantity": 100 } }'
For more information, you may check out this documentation:
Protocol specification for https.onCall
Related
I am trying to use OpenSearch Dashboards API (Amazon Kibana fork) to add a search index. I am using version 1.0 and have also setup the security plugin. I have no issues using TLS PKI for interacting with OpenSearch (Elasticsearch). However, whenever I try to interact with the OpenSearch Dashboard API with TLS PKI authentication, I get an error. I am able to setup PKI within Dashboards to authenticate to OpenSearch without any issues. Here is effectively the command on the shell using curl, but I am looking to use python when finished:
curl -X POST --cert MYCERT.crt --key MYKEY.key --cacert MY-CA-BUNDLE.crt https://HOSTNAME:5601/api/saved_objects/index-pattern/test-index -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d' { "attributes": { "title": "test-index-*","timeFieldName": "#timestamp" } }'
I get the following JSON message error back:
{"statusCode":401,"error":"Unauthorized","message":"Authentication required"}
If I instead use the API with 'simple' username/password, the same command works:
curl -X POST -u USERNAME:PASSWORD https://HOSTNAME:5601/api/saved_objects/index-pattern/test-index -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d' { "attributes": { "title": "test-index-*","timeFieldName": "#timestamp" } }'
However, I can't seem to find a way to allow my ansible to issue a command to the API using PKI certificates, which I am looking to do so I can disable simple authentication. Does anyone know what setting I am missing or if I am misusing the API? I have studied the plugin documentation, but I can't find any item that I am missing.
Did you try a simple query to Opensearch service like:
curl -XGET -k https://$(hostname):9200/ --key MYKEY.key --cert MYCERT.crt
If this one is not working, probably you need to check the certificates that are configured in opensearch.yml file.
I am developing an app with swift and try integrating push notifications.
Firebase send push notifications via curl command works, but not from firebase console.
I followed every step from different tutorials, used the AuthKey, the bundle ID is correct and i do not receive any errors and the status of the push notification is "done/finished".
Here is the curl command i am using
curl --header "Content-Type: application/json" \
--header "Authorization: key="My Server Key"
https://fcm.googleapis.com/fcm/send \
-d '{"notification": {"body": "Hellof!", "sound": "default"},
"priority": "high",
"to": "FMC push token"}'
I hope someone has a solution for that problem or similar experience.
I too got it working in curl using a similar JSON structure as given by you. But in some cases it was resulting in null values for the body and title (I used the title field also)
It became better when I used "data" instead of "notification" in the JSON
Try changing the JSON as shown below. I have not tried it out myself in the exact context that you describe (Firebase console) but when I did that using CURL I found that both body and title are correctly being displayed in the notification
curl --header "Content-Type: application/json" \
--header "Authorization: key="My Server Key"
https://fcm.googleapis.com/fcm/send \
-d '{"data": {"title": "The Title","body": "Hellof!", "sound": "default"},
"priority": "high",
"to": "FMC push token"}'
How would I convert the following curl commands from the Lyft api to http interfaced requests (so they can be executed over web like https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY)? If http requests translation is not possible, how would I integrate and process these curl commands in R?
#Authentication code
curl -X POST -H "Content-Type: application/json" \
--user "<client_id>:<client_secret>" \
-d '{"grant_type": "client_credentials", "scope": "public"}' \
'https://api.lyft.com/oauth/token'
#Search query
curl --include -X GET -H 'Authorization: Bearer <access_token>' \
'https://api.lyft.com/v1/eta?lat=37.7833&lng=-122.4167'
Hi you could use https://curl.trillworks.com/ to convert curl commands to the language of your choice or you could use lyft SDK's (for Python use https://pypi.python.org/pypi/lyft_rides).
Here is the corresponding Python version
import requests
headers = {
'Content-Type': 'application/json',
}
data = '{"grant_type": "client_credentials", "scope": "public"}'
requests.post('https://api.lyft.com/oauth/token', headers=headers, data=data, auth=('<client_id>', '<client_secret>'))
From this post request you will get access token that has to be used for subsequent requests.
headers = {
'Authorization': 'Bearer <access_token>',
}
requests.get('https://api.lyft.com/v1/eta?lat=37.7833&lng=-122.4167', headers=headers)
Note: I haven't tested this as I am unable to create a lyft developer account so there might be some minor changes in the code given here.
[Full disclosure: I'm a Developer Advocate at Lyft] I'm not very familiar with R, but could you integrate the responses/calls using the method described in this blog post?
https://www.r-bloggers.com/accessing-apis-from-r-and-a-little-r-programming/
ReqBin can automatically convert Curl commands to HTTP requests
An example of such request:
Convert Curl to HTTP Request
I am using stripe to update the card on a managed account external_account, but the error is asking for a token but the docs are saying wither token or dictionary.
https://stripe.com/docs/api#account_create_card
-d external_account={"object":"card", "exp_month":"04", "exp_year":"2019", "number":"5200828282828210"}
Error
{
"error": {
"type": "invalid_request_error",
"message": "Received unknown parameter: number",
"param": "number"
}
}
The reason that your example curl command doesn't work is that the Stripe API requires that the Content-Type header of requests sent to it be application/x-www-form-urlencoded and you are sending a JSON string.
curl https://api.stripe.com/v1/accounts/acct_XXYYZZ/external_accounts \
-u sk_test_AABBCC: \
-d external_account[object]="card" \
-d external_account[number]=5200828282828210 \
-d external_account[exp_month]=04 \
-d external_account[exp_year]=2019 \
-d external_account[cvc]=123
From the curl man-page, the "-d" switch on the curl command "Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded" which what you want, and the square bracket notation is how you send a hash/dictionary as Content-Type: application/x-www-form-urlencoded.
We are trying to create users in Fiware IDM using Keystone Identity API.
We are sending the following curl command
curl -s \
-H "X-Auth-Token: e746971040657101bb1e" \
-H "Content-Type: application/json" \
-d '{"user": {"name": "newuser", "password": "changeme"}}' \
http://localhost:35357/v3/users | python -mjson.tool
The token we have used is the one configured in keystone.conf
admin_token=e746971040657101bb1e
But the result we are getting is the following
{
"error": {
"code": 401,
"message": "The request you have made requires authentication.",
"title": "Unauthorized"
}
}
Does anyone have an idea about what can happen?
A couple of ideas for you.
One is that the port value 35357 is not for the admin API calls, it's intended for user calls.
Also since you are using the v3 API I believe that the token can't be used when creating a user unless you are indicating a domain.
However I can't tell from your curl command what action you are trying to do.