CloudKit Subscriptions "Expected this response but could not parse it"

So I'm trying to create a new subscription based on a predicate. The predicate is if there is a new Record (of type Message) with conversationID to a given conversation ID.

Okay so I've enabled notifications on my device and subscriptions do get sent to CloudKit. But then when I go onto the CloudKit dashboard I get this response:

Error fetching subscriptions.
Expected this response but could not parse it: HTTP 200, text: [{"subscriptions":[{"type":"query","subscriptionId":"CDF6D9BD-77E5-41C6-BC18-3AD1A49E1A7D","query":{"recordType":"Message","filters":{"fieldName":"conversationID","fieldValue":{"type":"stringType","value":"C8356727-83A0-4981-9C62-48B891B376EB"},"type":"EQUALS"}]},"firesOn":["CREATE"],"firesOnce":false,"zone":{"zoneName":"_zoneWide","canonicalName":"_zoneWide","ownerRecordName":"_df807ec5aa88995e336922b90835b528"}}]}

So I'm confused about this.

It seems like that is the response I was looking for, and I'm not sure why it can't query it. I remember seeing in another question something about there being an issue with a listEmpty or something.

But I'm querying on a string so I don't understand why it's not working.

my CloudKit code looks like this:

func setNotifications(convoID: String) {
    let database = CKContainer.default().publicCloudDatabase
    let pred = NSPredicate(format: "conversationID == %@", convoID)
    let newSubscription = CKQuerySubscription(recordType: RecordType.Message, predicate: pred, options: [.firesOnRecordCreation])

    let notification = CKSubscription.NotificationInfo()
    notification.alertBody = "You have a new message"
    notification.shouldSendContentAvailable = true
    newSubscription.notificationInfo = notification

    database.save(newSubscription) { (subscription, error) in
         if let error = error {
              print(error)
              return
         }

         if let _ = subscription {
              print("Hurrah! We have a subscription")
         }
    }
}

Thanks!

Answered by elijahahmad in 686596022

CloudKit was undergoing an update. Seems like everything is sorted now :)

Thanks for bringing this to our attention.

Did you copy that error text exactly as it appeared? If so, although the text looks like JSON, it's not valid. The first [ shouldn't be there and there should be a [ after "filters": and this would be a server-side issue.

If you can reproduce the issue again, could you post the X-Apple-Request-UUID response header value, please?

Oh yeah I didn't copy it properly because it was quite long. Heres the entire issue:

Error fetching subscriptions. Expected this response but could not parse it: HTTP 200, text: {"subscriptions":[{"type":"query","subscriptionId":"CDF6D9BD-77E5-41C6-BC18-3AD1A49E1A7D","query":{"recordType":"Message","filters":[{"fieldName":"conversationID","fieldValue":{"type":"stringType","value":"C8356727-83A0-4981-9C62-48B891B376EB"},"type":"EQUALS"}]},"firesOn":["CREATE"],"firesOnce":false,"zone":{"zoneName":"_zoneWide","canonicalName":"_zoneWide","ownerRecordName":"_df807ec5aa88995e336922b90835b528"}},{"type":"query","subscriptionId":"75FD4B36-F48F-46BD-962B-BA0BA16231C5","query":{"recordType":"Message","filters":[{"fieldName":"conversationID","fieldValue":{"type":"stringType","value":"F46D6D9A-6721-4474-92B9-84CE6D327CDB"},"type":"EQUALS"}]},"firesOn":["CREATE"],"firesOnce":false,"zone":{"zoneName":"_zoneWide","canonicalName":"_zoneWide","ownerRecordName":"_df807ec5aa88995e336922b90835b528"}},{"type":"query","subscriptionId":"127FC165-7A43-46F0-BB4A-EDB251AD5DAB","query":{"recordType":"Message","filters":[{"fieldName":"conversationID","fieldValue":{"type":"stringType","value":"EFD26729-47F3-46C4-9BA2-2AC24F0122D3"},"type":"EQUALS"}]},"firesOn":["DELETE","CREATE"],"firesOnce":false,"zone":{"zoneName":"_zoneWide","canonicalName":"_zoneWide","ownerRecordName":"_df807ec5aa88995e336922b90835b528"}},{"type":"query","subscriptionId":"2D2D391B-E9BE-434C-BCD7-F7D323D28600","query":{"recordType":"Message","filters":[{"fieldName":"conversationID","fieldValue":{"type":"stringType","value":"C26242A7-3C18-4586-B82F-3C1F0957FEB3"},"type":"EQUALS"}]},"firesOn":["DELETE","CREATE"],"firesOnce":false,"zone":{"zoneName":"_zoneWide","canonicalName":"_zoneWide","ownerRecordName":"_df807ec5aa88995e336922b90835b528"}}]} Please try again later.

I tried finding the response value but it am not sure where to find that.

Update - Adjusted predicate to"conversationID = %@", removed the predicate completely, forced single subscription per request, the updated result is similar: Error fetching subscriptions. Expected this response but could not parse it: HTTP 200, text: {"subscriptions":[{"type":"query","subscriptionId":"D100BAE0-D9C1-4A48-A3D1-6A6D2EE3733B","query":{"recordType":"Message","filters":[]},"firesOn":["CREATE"],"firesOnce":false,"zone":{"zoneName":"_zoneWide","canonicalName":"_zoneWide","ownerRecordName":"_df807ec5aa88995e336922b90835b528"}}]} Please try again later.

Getting the same error this morning. Nothing has changed in my apps database. Closing the browser helped once, then it started happening again. Have a strong feeling it's completely server side. Never seen this error before.

Thanks for the additional information. We've been able to identify the underlying cause.

Accepted Answer

CloudKit was undergoing an update. Seems like everything is sorted now :)

We can confirm that a fix was deployed September 1st, 2021.

CloudKit Subscriptions "Expected this response but could not parse it"
 
 
Q