0

I am trying to use curl command line code to access my custom model on google cloud, However an annoying error keeps popping. Here is the error: Invalid JSON payload.

I followed the autoML curl code on these sites, but to no avail: prediction with curl on custom model

I even tried building my own JSON file with the parameters needed using the API provided by google here: Google AutoML Translation API.

I hope someone can help me with this issue. Thank you very much for your time.

Here my curl code that i am using:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://automl.googleapis.com/v1beta1/projects/PROJECT_ID/locations/us- 
central1/models/MODEL_ID:predict \
-d @request.json`

and my request.JSON file

'{
  "payload": 
         {
            "textSnippet": 
             {
                "content": "hello world",
                "mimeType": "",
                "contentUri": ""
             }
         },
  "params":
         {
           "string": ""
         }
}'
adm
  • 135
  • 10

1 Answers1

1

Invaild JSON

(according to Google API)

One thing wrong is that your params is in the wrong place according to the docs.

{
   "payload": 
    {
        "textSnippet": 
        {
            "content": "hello world",
            "mimeType": "",
            "contentUri": ""
        }
    },
    "params":
    {
        "string": ""
    }
 }

Also you JSON you need to wrap everything in quotes. You were missing quotes around the 'string'.

{
    string: ""
}

Your payload needs to be exactly what it's looking for:

Required. Payload to perform a prediction on. The payload must match the problem type that the model was trained to solve.

Sources: AutoML Example-Payload

Haley Mueller
  • 487
  • 4
  • 16
  • @adm I edited my answer. Is your payload code exactly what it is looking for? Also you might be able to find more information if you click my source on 'Example-Payload' – Haley Mueller Mar 19 '19 at 22:05
  • It did not work. I think maybe their code and their documentation is not in sync,like there are other stuff to parse and the contentUri is not clearly defined in their documentation. I'm frustrated spent over 4 hours trying to solve it. :/ @Mark – adm Mar 19 '19 at 22:05
  • yes i went through payload, text snippet and created this json file and failed. Still the same man :/ @Mark – adm Mar 19 '19 at 22:19