google-cloud-platformgoogle-cloud-automl

Invalid JSON payload received. Unknown name \"row\" at 'payload': Cannot find field on google automl api


I am trying to implement google automl api: https://cloud.google.com/automl-tables/docs/predict

The api docs says I need to post data in following format:

{
  "payload": {
    "row": {
     "values": [value1, value2,...]
         }
      }
}

But when I to post data in same format I get the following error:

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"row\" at 'payload': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
    "@type": "type.googleapis.com/google.rpc.BadRequest",
    "fieldViolations": [
      {
        "field": "payload",
        "description": "Invalid JSON payload received. Unknown name \"row\" at 'payload': Cannot find field."
      }
    ]
      }
    ]
  }
}

Here is my curl request:

curl --location --request POST 'https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/TBLID:predict' \
--header 'Content-Type: application/json; charset=utf-8;' \
--header 'Accept-Charset: utf-8' \
--header 'Authorization: Bearer token here' \
--data-raw '{
 "payload": {
"row": {
  "values": [
    "",
    "4.900000",
    ""
  ]
}
 }
}'

I am not sure what is causing this error. Can anyone help with this problem thanks


Solution

  • I have a project with AutoML tables and this is an example prediction request sent in which works fine and returns results without error:

    {
      "payload": {
        "row": {
          "values": [
            "2",
            "test text",
            "test text",
            "21",
            "0",
            "0",
            "test text",
            "10",
            "",
            "S"
          ]
        }
      }
    }
    

    If you're not sure how to submit data or you are getting errors, go to your project in the console and to your AutoML Tables model and click "Test and Use". Then, follow these directions for getting an online prediction from console. Pay attention to the JSON Code View which will give you the exact input and let you test your JSON input as well.

    To test, I submitted the following curl request (with some identifying characters changed)

    curl -X POST \
    -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    https://automl.googleapis.com/v1beta1/projects/this-isnt-a-real-project-id/locations/us-central1/models/TBL123451234512345:predict
    

    My request.json file in the same directory that I sent the request from was:

    {
        "payload": {
          "row": {
            "values": [
              "yes",
              "-1",
              "primary",
              "jul",
              "51",
              "0",
              "yes",
              "no",
              "88",
              "cellular",
              "blue-collar",
              "unknown",
              "10",
              "620",
              "married"
            ]
          }
        }
      }
    

    The response was:

    {
      "payload": [
        {
          "tables": {
            "score": 0.9999906,
            "value": "no"
          }
        },
        {
          "tables": {
            "score": 9.42341e-06,
            "value": "yes"
          }
        }
      ]
    }
    

    I also repeated this same request in postman successfully below:

    curl --location --request POST 'https://automl.googleapis.com/v1beta1/projects/this-isnt-a-real-project-id/locations/us-central1/models/TBL123451234512345:predict' \
    --header 'Accept-Charset: utf-8' \
    --header 'Authorization: Bearer abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "payload": {
          "row": {
            "values": [
              "yes",
              "-1",
              "primary",
              "jul",
              "51",
              "0",
              "yes",
              "no",
              "88",
              "cellular",
              "blue-collar",
              "unknown",
              "10",
              "620",
              "married"
            ]
          }
        }
      }'