I'm trying to use the CloudKit API to create records in the public database from my server, using a server-to-server key. I'm using the following shell script to generate the curl command. When I run it, the response from Apple just says there was an internal error.
{ "uuid" : "a6415feb-168b-4615-9577-10c5168d7d7c", "serverErrorCode" : "INTERNAL_ERROR" }
This is the script I'm using:
#!/bin/sh
subpath=/database/1/iCloud.com.mycompany.myapp/development/public/records/modify
date=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
body='
{
"operations": [
{
"operationType": "forceReplace",
"record": {
"recordType": "Drawing",
"fields": {
"date": "2021-01-09T12:00:00Z",
"numbers": [14, 26, 38, 45, 46, 13],
"type": 1
}
},
"recordName": "powerball20210109"
}
],
"atomic": true
}
'
encoded=`echo $body | base64`
signature="$date:$encoded:$subpath"
curl -X POST https://api.apple-cloudkit.com$subpath \
-H 'Content-Type: application/json' \
-H 'X-Apple-Cloudkit-Request-KeyID: myKeyHere' \
-H "X-Apple-CloudKit-Request-ISO8601Date: $date" \
-H "X-Apple-CloudKit-Request-SignatureV1: $signature" \
-d "$body"
The CloudKit schema shows Drawing as a custom type with three properties:
- date is a Date/Time
- numbers is an Int(64) (List)
- type is an Int(64)