如何在Firebase中使用REST API进行多path更新? 错误400

我想使用firebase REST API和Vapor框架在单个操作中更新多个节点。 当我向Firebase发出.patch请求时,我从Vapor客户端收到错误消息:

操作无法完成。 错误400错误请求

任何人都可以告诉我,如果finalDictionary被正确初始化之前在JSON转换?

用户所需的输出节点:

  brv-61e24 Users usersUID customer bookingNumber timeStampBookingCancelled CleanersUID:"cleanersUID" TimeStampBookingClaimed: "TimeStampBookingClaimed" TimeStampBookingCancelledByCleaner: "TimeStampBookingCancelledByCleaner" Cleaners cleanersUID bookingNumber timeStampBookingCancelled TimeStampBookingClaimed:"TimeStampBookingClaimed" TimeStampBookingCancelledByCleaner: "TimeStampBookingCancelledByCleaner" Cleaners cleanersUID bookingNumber Claimed: "ClaimedValue" var finalJSON:JSON? func makeFinalDictionary() throws -> JSON? { let customer = userStripeIdCustomer var finalDictionary = Node([:]) //create base paths let path0 = "Users/\(usersUID!)/\(customer!)/\(bookingNumber!)/timeStampBookingCancelled" let path1 = "Cleaners/\(cleanersUID!)/\(bookingNumber!)/timeStampBookingCancelled" let path2 = "Cleaners/\(cleanersUID!)/\(bookingNumber!)" //create final paths and assign values to keys finalDictionary[path0] = try Node(node: ["CleanersUID": cleanersUID]) finalDictionary[path0] = try Node(node:["TimeStampBookingClaimed":timeStampBookingClaimed]) finalDictionary[path0] = try Node(node:["TimeStampBookingCancelledByCleaner":timeStampBookingCancelledByCleaner]) finalDictionary[path1] = try Node(node:["TimeStampBookingClaimed":timeStampBookingClaimed]) finalDictionary[path1] = try Node(node:["TimeStampBookingCancelledByCleaner":timeStampBookingCancelledByCleaner]) finalDictionary[path2] = try Node(node:["Claimed":claimedValue]) do { finalJSON = try JSON(Node(node:finalDictionary)) } catch let error as NSError { let message = error.localizedDescription drop.log.error(message) throw NSError(domain: "errorFirebase", code: error.code, userInfo: ["error" : message]) } return finalJSON } func writeAsMultiPath(tokenReceived:String!, jsonObject:JSON?) throws -> Void { let responseFirebase:Response? do{ let token = tokenReceived ?? "defaultValue" let response = try drop.client.patch( "https://brv-61e24.firebaseio.com.json/", headers: ["Authorization":"Bearer \(tokenReceived)"], query: [:], body: jsonObject!) responseFirebase = response }catch let error as NSError { guard let phrase = error.userInfo["error"] as? String else { throw NSError(domain: "errorFirebase", code: error.code, userInfo: ["error" : error.localizedDescription]) } throw NSError(domain: "errorFirebase", code: error.code, userInfo: ["error" : phrase]) } let body = responseFirebase?.body.bytes do { jsonFromWritingUsers = try JSON(bytes:body!) } catch let error as NSError{ let message = "jsonFromWritingUsers cannot be converted in JSON line 408 in\(fileName)" drop.log.error(message) throw NSError(domain: "errorFirebase", code: error.code, userInfo: ["error" : message]) } guard responseFirebase?.status.statusCode == 200 else{ let message1 = "write as multi-path failed line 410 in\(fileName)" drop.log.error(message1) let message = "fail" throw NSError(domain: "errorFirebase", code: 400, userInfo: ["error" : message]) } } 

Interesting Posts