Why do i get 400 using AutoML Rest API? - rest

I trained a custom model using Google Cloud AutoML.
Now i am trying to access it, using the script provided by Google.
I tried to vary "content" in any kind of ways.
I also had a look at the information provided here. Surely i did provide the correct path to the key file. Also i checked on the project ID and model ID.
I do have a service account. Billing is enabled too.
export GOOGLE_APPLICATION_CREDENTIALS={key-file-path}
curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
https://automl.googleapis.com/v1beta1/projects/{my-project-ID}/locations/us-central1/models/{my-model-id}:predict \
-d '{
"payload" : {
"textSnippet": {
"content": "happy",
"mime_type": "text/plain"
},
}
}'
I expect the result to be the prediction.
My result looks like this:
"error": {
"code": 400,
"message": "Invalid JSON payload received. Expected a value.\n“happy”,\n \n^",
"status": "INVALID_ARGUMENT"}

Thanks for your comments, John Hanley and Phillipp Möhler!
Actually I can't really tell what happened here.
I followed Johns advice to use a whole sentence. Doing that enabled me to successfully predict something!
Afterwards I was able to use both, single words and sentences.
Deleting the commas seems to have no effect at all.

Related

How to change confluent rest proxy body data schema for producing messages

The confluent rest proxy documents suggest that to post a data it must be as such:
$ curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json" \
--data '{"records":[{"value":{"name": "testUser"}}]}' \
"http://localhost:8082/topics/jsontest"
namely, every post data must be wrapped inside the following schema:
{"records":[
{"value":{<DATA>}}
]}
I was wondering if it's possible to change this schema? For instance, I might want to change records to log and include my data as inside an array as the value to the log as follows:
{"log": [<my_data>, <my_data>] }
How can I go about this?
The API is defined in the documentation and states the format that your payload must take.
If you want to batch your records together you need to do so within the defined schema, e.g.
curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json" \
--data '{ "records": [ { "value": { "name": "testUser1" } }, { "value": { "name": "testUser2" } } ] }' \
"http://localhost:8082/topics/jsontest"
AFAIK the only way to support the schema you're talking about would be to modify the source code yourself.

Curl command not working for Zapier REST hook

I am making a Zapier App that will contain a basic trigger. I am using REST hook in API configuration. I followed the instructed steps and everything is fine. At the End i get a Webhook URL, when i am creating a Zap.
As per my understanding, i will be using this URL to send POST request. So i use curl terminal command.
curl -X POST -H 'Content-type: application/json' --data '{ message: 'lemon', id: 'abc', season: 'summerTime' }' https://hooks.zapier.com/hooks/catch/7459492/XXXXXX/
I get response
{"id": "8e5bc4fb-a54c-4860-a22f-8896fadc95a1", "request_id": "5eb3c0c0-9a44-4543-81ba-87cd1a0793b0", "attempt": "5eb3c0c0-9a44-4543-81ba-87cd1a0793b0", "status": "success"}
But nothing happens.
This trigger is suppose to print message and season in some slack channel, i.e Zap i created.
Even in task log, no log is generated.
PS: when i do the same POST request with POSTMAN application, it works just
fine. Can anyone tell me what am i doing wrong.
I am new to these stuff.
I believe you're missing quotes around your keys in the data. Try this:
curl -X POST -H 'Content-type: application/json' --data '{ "message": "lemon", "id": "abc", "season": "summerTime" }' https://hooks.zapier.com/hooks/catch/7459492/XXXXXX/
Note that you can "copy as curl" from postman and emulate exactly what it's doing.

Facebook Messenger bot welcome message: 100 The parameter setting_type is required

I'm trying to set a welcome message for a Facebook Messenger bot using the code provided in the documentation - with my own page ID and page access token
curl -X POST -H "Content-Type: application/json" -d '{
"setting_type":"call_to_actions",
"thread_state":"new_thread",
"call_to_actions":[{
"message":{
"text":"Hello! This is a Messenger bot!"
}
}]
}' "https://graph.facebook.com/v2.6/<PAGE_ID>/thread_settings?access_token=<PAGE_ACCESS_TOKEN>"
This returns the following:
{"error":{"message":"(#100) The parameter setting_type is required","type":"OAuthException","code":100,"fbtrace_id":"B0DKyn9O2KB"}}
Any ideas on how to solve this? Thanks.
I had the same problem! Some strange copy/paste error with the cURL command from fb...
It didn't work with cURL, but then I used "Advanced REST client" (Chrome plugin) and I was able to set the Welcome Message.
I've tried those exact params with my own page and they worked fine.
Can you try these steps?
Get your page ID and a fresh access token from the Facebook developer console
Make the request from https://developers.facebook.com/tools/explorer to make sure it isn't a problem with cURL
I was having the same issue and the reason was just stupid:
I made copy paste from FB doc and some quotes were wrong. They were ” instead of ".
Open your file in vi or something and search for all quotes so that u can easily understand which are wrong.
I had the same issue, i solved it be calling the URL by postman.check image
There seems to be a problem with windows cmd interpreting the commands. Can you try the same code using Cygwin. It worked well for me. Cheers
this is what works for me
curl --location --request POST 'https://graph.facebook.com/v13.0/your_api_id/messages' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer your_App_Token' \
--data-raw '{
"messaging_product": "whatsapp",
"preview_url": false,
"recipient_type": "individual",
"to": "33732473829",
"type": "text",
"text": {
"body": "Hello,"
}
}'
I had to specify the access token in the header

Creating JIRA issue using curl from command line

I've been through documentation here according to which I'm creating a issue for JIRA . I know I'm making some terribly small mistake .
I'm trying to create a new JIRA request from command line (later I'll integrate in my java code)
From my Mac terminal I'm trying to run :
curl -D- -u username:password -X POST --data {"fields":{"project":{"key": “PROJECTKEY"},"summary": "REST ye merry gentlemen.","description": "Creating of an issue using project keys and issue type names using the REST API","issuetype": {"name": "Bug"}}} -H "Content-Type: application/json" https://mycompanyname.atlassian.net/rest/api/2/issue/
I believe this has something to do with the "data".
Thanks in advance. The example has been taken from the documentation link itself.
OUTPUT : I'm getting nothing in my terminal, no error, no expected output .
PROJECTKEY is taken from the KEY column from the All Project list in my DASHBOARD.
Two things are off:
you need to put the data that you want to post in quotes
the first double quote surrounding PROJECT_KEY is a unicode character instead of a regular double quote, so change “PROJECTKEY" to "PROJECTKEY"
This should work:
curl -D- -u username:password -X POST --data '{"fields":{"project":{"key": "PROJECTKEY"},"summary": "REST ye merry gentlemen.","description": "Creating of an issue using project keys and issue type names using the REST API","issuetype": {"name": "Bug"}}}' -H "Content-Type: application/json" https://mycompanyname.atlassian.net/rest/api/2/issue/

Create GitHub.com Hook

I am attempting to create a hook using the create hook api found on
http://developer.github.com/v3/repos/hooks/#create-a-hook
but I am getting a 301 when I attempt to post, so I am sure I am doing it wrong...
A couple of questions...
1) How does github know that I can create a hook for that repo if it is private? I am sure I need to authenticate with the POST, but how?
2) Is the following curl statement a valid example of how to create a hook?
curl -v -H "Content-Type: application/json" -X POST -d "{ "name": "cia",
"active": true, "events": [ "push" ], "config": {
"url": "http://requestb.in/######", "content_type": "json" } }"
http://github.com/repos/#####/#####/hooks
I have replaced certain elements with ##### for security sake...
3) If the above is incorrect, may I please have a snippet of a valid example to create a hook for the webhook named "cia"?
curl -usigmavirus24 -v -H "Content-Type: application/json" -X POST -d '{"name": "cia", "active": true, "events": ["push"], "config": {"url": "...", "content_type": "json"}}' https://api.github.com/repos/sigmavirus24/reponame/hooks
Is the correct curl command. The URL you're posting to has to be https://api.github.com/:endpoint where :endpoint in this case is repos/username/reponame/hooks. You also need to use 's around the JSON body for the curl command because otherwise you'll get strings like "{ " concatenated with the output of commands like name, cia, active, events, etc.
Also the -u :username option is necessary for curl so it will tell curl that it MUST authenticate and ask you for the password to do so.
If you don't mind your password being in your bash history (WHICH YOU SHOULD) you can also do -u username:password. Or even better you can base64 encode your credentials in the form username:password and then send that as a header like so: Authentication: Basic <base64-encoded-credentials.