Search code examples
phpjsoncloudkitcloudkit-web-services

How to do a CloudKit record lookup with recordName?


I am trying to do a lookup from a CloudKit database via a PHP script.

The CloudKit documentation for doing a lookup says that a lookup request requires a JSON dictionary with a records key pointing to an array of Lookup Record Dictionaries that provide, at least, a recordName for each record to be fetched.

I have a PHP script that sends:

$request ='{
    "records":[
    {"recordName":"'.$record.'"}
    ]
}';

Which what I think I am supposed to send, but I get back the following error:

["uuid"]=> string(36) "96e33481-9fb0-4ce8-9cd1-34b6617a3d5b" ["serverErrorCode"]=> string(11) "BAD_REQUEST" ["reason"]=> string(61) "BadRequestException: Unexpected input at [line: 1, column: 0]"

echoing out $request gives me:

{ "records":[ {"recordName":"Newest_T_Guyig"} ] }

And this passes JSON lint as valid. Obviously I'm sending the wrong data, but I can't see what I am doing wrong.

The error message suggests I'm leaving something out that's required, but it's not clear from the docs what that might be.

Can someone please explain what is wrong here? My imperfect understanding of JSON may the fault.

A similar question to this one has been asked, but its links to Apple documentation are broken/ out of date.


Solution

  • There was an obscure problem elsewhere in my script that, once fixed, solved the issue. It had nothing to do with the JSON which turns out to be correct.