HTTP POST Invalid field name xxx for type ApiRequestEntity

#1

I am making a HTTP POST request to an action in the environment and received this error

{u'message': u'Invalid field name xxx for type ApiRequestEntity at JSON document at 1:20', u'codes': [u'BadField'], u'id': u'2988.257'}

I am using this command to make the request.
requests.post(url, data=json.dumps(data), headers = headers)

url is like https://evironment/api/1/tenant/tag/EntityType?action=function
and the function accepts data as argument.

Any thoughts on how to solve this error? Please let me know. Thank you.

0 Likes

#2

It look like your data contains an extra field for the action function.

Lets say your action fct is declared like:

fct: function(arg1: string, arg2: json): .....

then payload of your POST request should be something like:

{
  "arg1": "value_for_arg1",
  "arg2": {
    ... // json object
  }
}
0 Likes

#4

The function takes in a spec - C3 Type and I am sending in a JSON with fields present in the Type. Should I make any changes to design ?

0 Likes

#5

no it should be OK, the payload should look like:

{
   "spec": {
   // json with all or a subset of the field from your type
   }
}

E,g, payload for Facility.fetch which accepts a FetchSpec:

{
  "spec": {
     "filter": ".parent.id=='1'",
     "order": "start",
     "include": "id, name"
  }
}
1 Like

#6

Ok. I changed the payload and get this as the response. It seems token ‘spec’ is not recognized…

{u'message': u'Parsing failed!', u'codes': [u'ParsingFailed'], u'cause': {u'message': u"Unrecognized token 'spec': was expecting ('true', 'false' or 'null')\n at [Source: java.io.InputStreamReader@7d335e91; line: 1, column: 5]"}, u'id': u'2988.371'}

0 Likes

#7

You can make the function call in the static console first. In the network tab in developer tools in chrome, you will find the network request from the function call. It contains the url, payload, and headers. Try replicating those in your http request.

0 Likes