orientechnologies / orientdb-studio

Studio web tool
Other
127 stars 50 forks source link

create edge issue with REST API #530

Open henryagyei opened 5 years ago

henryagyei commented 5 years ago

Im using the rest api version 2.2 to create edges but continously receive error code 400 even though I am creating exactly the same was as in REST API docs. Please help with where I am going wrong. Code is in Swift

self.urlLink = http://:/batch/demodb let url = NSMutableURLRequest(url: self.urlLink!) url.httpMethod = "POST" let graphValues = ["transaction" : true, "operations" : [["type" : "cmd", "language" : "sql", "command" : "create edge Likes from #14.0 to #17.0"]]] as [String : Any] do { url.httpBody = try JSONSerialization.data(withJSONObject: graphValues, options: .prettyPrinted) // pass dictionary to nsdata object and set it as request body } catch let error { print(error.localizedDescription) }

    //create the session object
    let session = URLSession.shared

    let username = "root"
    let password = "password"
    let loginData = String(format: "%@:%@", username, password).data(using: String.Encoding.utf8)!
    let base64LoginData = loginData.base64EncodedString()

    url.addValue("application/json", forHTTPHeaderField: "Content-Type")
    url.addValue("application/json", forHTTPHeaderField: "Accept")
    url.addValue("gzip,deflate", forHTTPHeaderField: "Accept-Encoding")
    url.setValue("Basic \(base64LoginData)", forHTTPHeaderField: "Authorization")

    //create dataTask using the session object to send data to the server
    let task = session.dataTask(with: url as URLRequest, completionHandler: { data, response, error in

        guard error == nil else {
            return
        }

        guard let data = data else {
            return
        }

        do {
            //create json object from data
            if let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any] {
                print(json)
             }

        } catch let error {
            print(error.localizedDescription)
        }
    })
    task.resume()

///Error im receiving is: ["errors": <__NSArrayM 0x282e3f510>( { code = 400; content = "Error parsing query:\ncreate edge Likes from #14.0 to #17.0\n ^\nEncountered \" \"create \"\" at line 1, column 1.\nWas expecting one of:\n