Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create edge issue with REST API #530

Open
henryagyei opened this issue Sep 30, 2019 · 0 comments
Open

create edge issue with REST API #530

henryagyei opened this issue Sep 30, 2019 · 0 comments

Comments

@henryagyei
Copy link

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 ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n ...\n \n\tDB name="demo""; reason = 400; } ) ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant