Invalid Argument on API Call? - google-api

I am getting an invalid argument with the following API Call (following https://developers.google.com/nest/device-access/api/doorbell-battery#webrtc):
curl -X POST 'https://smartdevicemanagement.googleapis.com/v1/enterprises/projectID/devices/deviceID:executeCommand' -H 'Content-Type: application/json'
-H 'Authorization: AUTHTOKEN' --data-raw '{
"command" : "sdm.devices.commands.CameraLiveStream.GenerateWebRtcStream",
"params" : {
"offerSdp" : "a=recvonly"
}
}'
Response from server:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
What is the invalid argument?

My impression is that is not a valid offer, and you need to use a web rtc client to create it. See webrtc.org for examples.

"offerSdp" : "a=recvonly" isn't a valid offer, but also you will get that INVALID_ARGUMENT error if you don't end your offer string with a \r\n character.

Related

laptop curl Youtube API v3 request always returns 'Exceeded Quota' error

Every time I attempt to use the following simple bash script command on my Macbook Pro laptop, I get an 'Exceeded Quota' error. I do supply a valid API key and I'm under the impression that I don't need any other tokens because I am only requesting Public information (a simple list of songs).
Bash script:
#!/bin/bash
curl \
'https://youtube.googleapis.com/youtube/v3/search?part=snippet&q=music&type=video&key=[My API key]' \
--header 'Accept: application/json' \
--compressed
Reply:
{
"error": {
"code": 403,
"message": "The request cannot be completed because you have exceeded your \u003ca href=\"/youtube/v3/getting-started#quota\"\u003equota\u003c/a\u003e.",
"errors": [
{
"message": "The request cannot be completed because you have exceeded your \u003ca href=\"/youtube/v3/getting-started#quota\"\u003equota\u003c/a\u003e.",
"domain": "youtube.quota",
"reason": "quotaExceeded"
}
]
}
}
I don't have any quota problems pulling song lists via the YouTube Data API 'list' page:
https://developers.google.com/youtube/v3/docs/search/list

Elastic Search is not working

When I am giving request to Elastic search my post and put is not working
My request
POST bird/admin/1
{
"id":"1",
"ity":"BSP"
}
It should give success
But, getting error
{
"error": "Content-Type header [application/x-www-form-urlencoded; charset=UTF-8] is not supported",
"status": 406
}
You should use application/json content type.
If you are using curl, add -H 'Content-Type: application/json'
https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests

Missing newline for adding with bulk API

I want to add the following file to Elasticsearch using the bulk API:
{"_id":{"date":"01-2007","profile":"Da","dgo":"DGO_E_AIEG","consumerType":"residential"},"value":{"min":120.42509,"minKwh":0.20071,"nbItems":6.0}}
using the command
curl -XPOST -H 'Content-Type: application/json' localhost:9200/_bulk --data-binary Downloads/bob/test.json
but I got the following mistake:
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\n]"}],"type":"illegal_argument_exception","reason":"The bulk request must be terminated by a newline [\n]"},"status":400}
NB: The file clearly has a empty line at the end
In the docs it says:
NOTE: the final line of data must end with a newline character \n.
There is an example above that of what the document is expected to look like. https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html. Perhaps adding \n at the end of each line would fix the issue.
UPDATE:
There might be something wrong with the way you have placed your data into your JSON file. For example, the following data is in example.json:
{ "index" : { "_index" : "example", "_type" : "doc", "_id" : "1" } }
{ "field1" : "value1" }
<space here>
When running the following curl command, it works:
curl -X POST -H "Content-Type: application/x-ndjson" localhost:9200/_bulk --data-binary "#example.json"
It could be that you're not including something important in your JSON file, or you don't have "#your_file.json", or like the other poster mentioned, you don't have the content-type as application/x-ndjson.
The answer is very simple
{ "index":{ "_index":"schools_gov", "_type":"school", "_id":"1" } }
{ "name":"Model School", "city":"Hyderabad"}
{ "index":{ "_index":"schools_gov", "_type":"school", "_id":"2" } }
{ "name":"Government School", "city":"Pune"}
is not going to work but the below json will work
{ "index":{ "_index":"schools_gov", "_type":"school", "_id":"1" } }
{ "name":"Model School", "city":"Hyderabad"}
{ "index":{ "_index":"schools_gov", "_type":"school", "_id":"2" } }
{ "name":"Government School", "city":"Pune"}
//Give a new line here. Not '\n' but the actual new line.
The HTTP command would be POST http://localhost:9200/schools_gov/_bulk
As the error states, you simply need to add a new line to the end of the file.
If you are on a *nix system, you can do this:
echo "\n" >> Downloads/bob/test.json
Also, as explained in the documentation https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html, the Content-Type should be application/x-ndjson
When sending requests to this endpoint the Content-Type header should
be set to application/x-ndjson
So the command should be:
curl -XPOST -H 'Content-Type: application/x-ndjson' localhost:9200/_bulk --data-binary Downloads/bob/test.json
The error message is very confusing. I typed -data-binary and got the same message. The message sent me to completely wrong direction.

I am getting this error in elasticsearch

{
"error":"Content-Type header [application/x-www-form-urlencoded] is not supported",
"status":406
}
Though I used header Content-Type
Here is the the command I used for indexing a customer document for a customer index:
curl -XPUT localhost:9200/customer/doc/1 -H 'Content-Type:application/json' -d '{"name":"abcd"}'

How do I map the JSON body of a GET request to a parameter?

I have the following definition in my endpoint:
params do
requires :entities do
requires :id, type: String
optional :email, type: String
optional :phone, type: String
end
end
post "test" do
end
Note this only works as a POST request and the following CURL will work:
curl -XPOST localhost/test
-H 'Content-Type: application/json'
-H 'Accept: application/json'
-d '{ "entities": [{ "id": 3, "email": "test#abc.com" }] }'
However, the moment I change the declaration to get "test" instead of post, the corresponding curl request with -XGET no longer works due to the following validation error:
{"error":"entities is missing"}
If I remove the params requirements I can manually inspect the params hash at runtime and see that it only has a single key "route_info"
I'm currently using Grape 0.7.0
It happens because by specifying -d option you pass parameters in the body of the request while your endpoint is expecting them in the path as part of the url. Check here why it's a bad idea to pass body parameters in a GET request.
However, can use that option but if combination with -G.
-G, --get
When used, this option will make all data specified with -d, --data, --data-binary or --data-urlencode to be used in an HTTP GET request
instead of the POST request that otherwise would be used. The data will be appended to the URL with a '?' separator.
So that your get request by using -d would look like:
curl -XGET -G localhost/test
-H 'Content-Type: application/json'
-H 'Accept: application/json'
-d '{ "entities": [{ "id": 3, "email": "test#abc.com" }] }'

Resources