phpiosswiftcloudkitcloudkit-web-services

How to Create CKReference using CloudKit Web Services?


I've using CK Web services very successfully, but I am stumped about how to create a CKReference.

I've looked at the docs here re Reference Dictionaries, but can't make such a dictionary work.

My php generates the following operations dictionary:

{"operations":[
{"operationType": "create",
"record": { "recordType": "Works",
     "fields": {
          "type":{"value":"Painting"},
          "title": {"value":"test"},
          "date": {"value":"10/29/1965"},
          "height": {"value":"21"},
          "length": {"value":"21"},
          "width": {"value":"21"},
          "runningTime": {"value":""},
          "materials": {"value":"test"},
          "description":{"value":"test"},
          "saleStatus": {"value":"yes"},
          "tos":{"value":"yes"},
          "artist": {"value":"Peter Wiley"},
          "artistRecordName":{"value":"286CB3BF-69CC-4DD3-9233-CC80E5FA95D4"},
          "artistRecordRef": {
               "recordName": {"value":"286CB3BF-69CC-4DD3-9233-CC80E5FA95D4"},         
               "zoneID":{"zoneName": {"value":"_defaultZone"}},
               "action": {"value":"NONE"}
          },
          "subject":{"value":""},
          "metaType":{"value":"Fine Art"},
          "userRecordName":{"value":"30C54AD8-3701-428C-99B7-0393DD2DAB45"},
          "userRole":{"value":"Artist"},
          "status":{"value":"P"}
     }
} }
]}

This request returns the error:

BAD_REQUEST" [1]=> string(62) "BadRequestException: Unexpected input at [line: 26, column: 3]

If I remove the "artistRecordRef" the request works as it should.

I am sure the answer is obvious to a more experienced eye. Can someone see what's wrong?


Solution

  • OK, I found the answer here, but have posted for others who may have the question because the answer was not easy to find.

    This is what works:

    "artistRecordRef": {"value": {
                    "recordName": "'.$artistRecordName.'",
                    "action": "NONE"
                }
            },
    

    The Reference Dictionary has to be passed as a value. I didn't get this and it's not well documented with examples in the Apple docs (at least in those I was able to find).

    See: How can I use CloudKit web services to query based on a reference field?