1

I'm trying to query CloudKit for a simple object where the name equals a string but I am getting back a BadRequestException.

The RecordType is "Teacher" with parameters "Name" and "Grade".

I'm guessing there is something wrong with my query filter but can't find anything out of spec for Apple's reference.

    {"query": {
          "filterBy": {
             "fieldName": "Name", "fieldValue": {
               "type": "STRING", "value": {
                "Name": "Teacher 1"
                }
              }, 
              "comparator": "EQUALS"
           }, 
        "recordType": "Teacher"
     }, 
   "zoneID": {"zoneName": "_defaultZone"}
}

Resulting Error:

{u'serverErrorCode': u'BAD_REQUEST', u'reason': u'BadRequestException: Invalid value, expected type STRING but actual value was object of class com.apple.cloudkit.ws.application.common.data.UnknownTypeModel', u'uuid': u'c254448d-130e-4c6c-8170-554d976a1789'}

adam0101
  • 1,198
  • 2
  • 16
  • 24
  • It's a little difficult to figure out which one of the above is a variable. Maybe you could expand the code snippet a little. but... Isn't teacher by any chance an object? – Lefty G Balogh Nov 03 '16 at 05:19
  • I updated the question with more details and expanded the filter query. – adam0101 Nov 03 '16 at 22:35
  • Can you try something for me and use `systemFieldName` instead of `fieldName`? – Lefty G Balogh Nov 04 '16 at 08:02
  • Same Exception but different error. BadRequestException: Unexpected input at [line: 1, column: 137]' – adam0101 Nov 04 '16 at 13:15
  • Check this out: http://www.hamagain.com/2016/09/30/cloudkitjs-error/ - looks like you are accidentally adding an extra "value:{}" to your query. – Lefty G Balogh Nov 04 '16 at 16:28
  • 1
    Lefty - You were really close, it wasn't the value that was wrong but it was putting the field name in again since I already have "Name" set in the "fieldName" parameter, in fieldValue it needed to be {"value":"Teacher 1"}. If you add that as an answer i'll accept it. – adam0101 Nov 04 '16 at 19:02
  • Done, I am glad you managed to figure it out. – Lefty G Balogh Nov 04 '16 at 20:47

1 Answers1

1

You do not need to put the field name in again, as "Name" is already set in the "fieldName" parameter. In fieldValue, it only needs to be {"value":"Teacher 1"}.

(The inspiration to the solution came from CloudKit JS Sample Code Error).

Lefty G Balogh
  • 1,771
  • 3
  • 26
  • 40