0
votes

I having some trouble accessing the REST API from Domino Access Service (9.0.1) via Alamofire in swift. My code looks like:

    Alamofire.request(.GET, dbPath)
        .authenticate(usingCredential: credential)
        .responseViewCollectionArray { (request, response, viewWrapper, error) in
            println("res: \(response)")
            if let anError = error {
                println("error \(anError)")
                completionHandler(nil, anError)
                return
            }
            println("success atPath")
            completionHandler(viewWrapper, nil)
    }

What brings me as result:

res: Optional( { URL: http://das.name.de/DASLib.nsf/api/data/collections } { status code: 404, headers { "Cache-Control" = "no-cache"; Connection = close; "Content-Length" = 220; "Content-Type" = "text/html; charset=US-ASCII"; Date = "Mon, 06 Apr 2015 06:41:37 GMT"; Expires = "Tue, 01 Jan 1980 06:00:00 GMT"; Server = "Lotus-Domino"; } }) error Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7fc911f01af0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}

So the content-type is wrong why I got an error when putting it into a JSON (swiftyJSON). I can see the "wrong" result using responseString instead of responseJSON from Alamofire. The strange part now is. When I am putting the end point in a rest client like CocoaRestClient it gives me a different content-type

HTTP 200 No Error

Content-Encoding: gzip Content-Length: 489 Vary: Accept-Encoding Content-Type: application/json Server: Lotus-Domino Date: Sun, 05 Apr 2015 19:41:28 GMT

If I am accessing a different part off the Domino-REST-API (e.g. the Databases on the Server) with the same code (only changing the end point). The code works well and I got the JSON.

So what am I missing? Maybe someone had the same problem when using REST via xPages in Domino.

1
Are you using session authentication and must authenticate to access that URL? Because if the credentials are wrong (or aren't send correctly with the request) Domino might return the login form (with the text/html content type) instead of the JSON feed.Mark Leusink
One has to understand the HTTP status codes (and not only rely on the HTTP Content-Type). The problem in this case cannot be authentication (sorry, Mark ;-)) as you're getting a HTTP status code 404. That means that the requested resource cannot be found (en.wikipedia.org/wiki/HTTP_404). In case of a missing/wrong session-based authentication on Domino you would get a HTTP status code 200 with Content-Type HTML (as Mark pointed out). Without further debugging information from the server (i. e. domlog) it's hard to define a solution.muenzpraeger
I am logging into my DB. For that I am using the credetial's [let credential = NSURLCredential(user: "name", password: "pwd", persistence: NSURLCredentialPersistence.ForSession)] I copied it from my working access class which access the viewCollection.Armin Mandel
Oops... missed the 404 in the response. I'll -1 myself ;)Mark Leusink

1 Answers

1
votes

As @muenzpraeger pointed out: you have a 404 - not found. Presuming that the resource does actually exist, it points to a configuration error. Most likely you haven't enabled the database or the view for access via DAS. I would be super-mega careful with DAS, once you allow WRITE access anybody who can reach the URL and has author or better access, can write back arbitrary documents and mess up your database (no validation!).

I'm working on some alternative (that also would return JSON on 404). Stay tuned