Query view with Public Port (user)

Even though I found the document said “Views are also available via the Public REST API (4984), and will automatically filter the returned data to the subset of the data which the user has access to.” in https://developer.couchbase.com/documentation/mobile/1.4/guides/sync-gateway/views/index.html
But i just failure to do so. it just returns “Forbidden”.

I set the user with “admin_channel”: ["*"] already. who can get all the documents and get the default view _all_docs. but can’t query the view created with Admin REST API.

I am using sync gateway 1.4. any advise or any thing I may miss?

@kelvin.wong could you paste the list of commands you used to create the view and then query it?

The view can be queried with admin port successfully… so i think it is correct.

it is created with javascript http.request

PUT /dbname/_design/testview HTTP/1.1
Host: syncgateway:4985
Content-Type: application/json
{ "views": { "users": { "map": "function (doc, meta) { if (doc.type == 'user') { emit(null, { 'id': doc.cid, 'firstName': doc.firstName, 'lastName': doc.lastName, 'fullName':  doc.fullName, 'mobileNo': doc.mobileNo, 'email':doc.email })}}" } } }

then the view will be created like

    "views": {
        "users": {
            "map": "function(doc,meta) {\n\t                    var sync = doc._sync;\n\t                    if (sync === undefined || meta.id.substring(0,6) == \"_sync:\")\n\t                      return;\n\t                    if ((sync.flags & 1) || sync.deleted)\n\t                      return;\n\t                    delete doc._sync;\n\t                    meta.rev = sync.rev;\n\t\t\t\t\t\t(function (doc, meta) { if (doc.type == 'user') { emit(null, { 'id': doc.cid, 'firstName': doc.firstName, 'lastName': doc.lastName, 'fullName':  doc.fullName, 'mobileNo': doc.mobileNo, 'email':doc.email }) }}) (doc, meta);\n\t\t\t\t\t\tdoc._sync = sync;}"

and query with following:

GET /dbname/_design/testview/_view/users HTTP/1.1
Host: syncgateway:4984
Authorization: Basic c3VwZXJVc2VyOkFCQzEyMzQ=
Content-Type: application/json

the user is created like

"superUser": {
   "disabled": false,
   "password": "ABC1234",
   "admin_channels": ["*"]

The Forbidden error implies that the user is not authorized to make the request.

Can you double check your configuration file and ensure it’s configured correctly to accept this request over public port as discussed here. I believe it is disabled by default.

Did you provide the right credentials in the Authorization header of the request?

Thanks~ it works now ~

So was it the configuration change?