Create Edge problem in REST API

Hi Community,

Im using the rest api version 2.2 to create edges but continously receive error code 400 even though I am creating i the same way as per REST API docs. Please help with where I am going wrong.

///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; } ) ]

The code used: (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]

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()

Hi @henry

do you have a standalone unit test that i can use to reproduce this?

If you run the same query from Studio does it work?

Thanks

Hi @wolf4ood

From Studio this works fine, the problem seems to be from any rest client.
This can be reproduced on Postman as per this attachment.

Thanks

31|690x419

Hi @henry

in this case seems a problem of url encoding
# and space are character that should be encoded before making the requests.

But in your code i guess you are using the body right?

Are you able to reproduce it with POST and body with postman?

Thanks

Hi @wolf4ood

Yes the problem persists when the command is in body also, as per below image.

Thanks

@henry

you are using the . #14.0 instead of #14:0

Thanks @wolf4ood, working now