Search code examples
phpjsoncurlgoogle-cloud-platformgoogle-cloud-automl

custom google cloud automl translation json request says Invalid JSON payload received


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

Solution

  • 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