phpjsoncloudkitcloudkit-web-services

How Do I read CloudKit Errors?


I have a php script that's trying to create a record in a CloudKit database.

It returns this error:

object(stdClass)#1 (3) { ["uuid"]=> string(36) "c70072a1-fab6-491b-a68f-03b9056223e1" ["serverErrorCode"]=>
string(11) "BAD_REQUEST" ["reason"]=> string(62) "BadRequestException: Unexpected input at [line: 2, column: 10]" }

I presume this tells me exactly what the problem is, but I don't know how to interpret it. Where is line 2 and column 10?

I think its related to the JSON I'm sending in the create record request.

$url = 'https://api.apple-cloudkit.com/database/1/' . $CONTAINER .    '/development/public/records/modify';
$opDict = '{"operationType": "create",
"record":"Artists",
"fields": {"firstName":{"value":"Mei"}, 
"lastName": {"value":"Chen"}, 
"principalDiscipline": {"value":""},
"secondaryDiscipline":{"value":""}},
"recordName":"Mei Chen"}';

$body = '{"operations":['.$opDict.']}';
echo $body; 

When I check the output from $body

{"operations":[{"operationType": "create", "record":"Artists", "fields": {"firstName":{"value":"Mei"}, "lastName": {"value":"Chen"}, "principalDiscipline": {"value":""}, "secondaryDiscipline":{"value":""}}, "recordName":"Mei Chen"}]}

it passes JSON lint, so I am not sure it is a JSON problem.

Can someone explain to me how to interpret the error I'm getting from CloudKit. The docs are a little vague on errors.


Solution

  • I got absolutely no clue about CloudKit, but I found this documentation page with the followin example:

    {
        "operationType" : "create",
        "record" : {
            "recordType" : "Artist",
            "fields" : {
                "firstName" : {"value" : "Mei"},
                "lastName" : {"value" : "Chen"}
            }
            "recordName" : "Mei Chen"
        },
    }
    

    which definitely differs from what you try to send, both in terms of data structure (your record is not a dictionary) and content (you have no recordType). So while your JSON is syntactically correct, you are simply sending invalid content data wrapped in valid JSON which is most likely the reason you are seeing the error message.