Data not syncing from couchbase lite to Couchbase(Unknown url error)

I am trying to sync data from couchbase lite to couchbase but unable to do so.
I am using Phonegap android to send data
I am getting 404 unknown URL error.

The following is my sync_gateway log

2019-02-22T15:15:06.876+05:30 [WRN] Using deprecated config option: log. Use logging.console.log_keys instead. -- rest.(*ServerConfig).deprecatedConfigLoggingFallback() at config.go:623

2019-02-22T15:15:06.876+05:30 [WRN] Deprecated log key: “CRUD+” found. Changing to: “CRUD”. – base.ToLogKey() at log_keys.go:158
2019-02-22T15:15:06.877+05:30 [WRN] Deprecated log key: “Shadow+” found. Changing to: “Shadow”. – base.ToLogKey() at log_keys.go:158
2019-02-22T15:15:06.877+05:30 [WRN] Deprecated log key: “Changes+” found. Changing to: “Changes”. – base.ToLogKey() at log_keys.go:158
2019-02-22T15:15:06.877+05:30 [ERR] No logFilePath configured, and --defaultLogFilePath flag is not set. Log files required for product support are not being generated. – base.(*LoggingConfig).Init() at logging_config.go:40
2019-02-22T15:15:06.877+05:30 ==== Couchbase Sync Gateway/2.1.2(2;35fe28e) ====
2019-02-22T15:15:06.877+05:30 [INF] Console LogKeys: [Access Cache Changes CRUD HTTP HTTP+ Shadow]
2019-02-22T15:15:06.877+05:30 [INF] Console LogLevel: info
2019-02-22T15:15:06.877+05:30 [INF] Log Redaction Level: none
2019-02-22T15:15:06.877+05:30 [INF] Opening db /techspin as bucket “default”, pool “default”, server http://192.168.1.15:8091
2019-02-22T15:15:06.877+05:30 [INF] GoCBCustomSGTranscoder Opening Couchbase database default on http://192.168.1.15:8091 as user “sync_gateway”
2019-02-22T15:15:06.881+05:30 [INF] Successfully opened bucket
2019-02-22T15:15:06.888+05:30 [INF] Design docs for current SG view version (2.1) found.
2019-02-22T15:15:06.888+05:30 [INF] Verifying view availability for bucket default…
2019-02-22T15:15:06.904+05:30 [INF] Views ready for bucket default.
2019-02-22T15:15:06.904+05:30 [INF] Cache: Initializing changes cache with options {ChannelCacheOptions:{ChannelCacheMinLength:0 ChannelCacheMaxLength:0 ChannelCacheAge:0s} CachePendingSeqMaxWait:5s CachePendingSeqMaxNum:10000 CacheSkippedSeqMaxWait:1h0m0s}
2019-02-22T15:15:06.904+05:30 [INF] Initializing changes cache for database techspin
2019-02-22T15:15:06.980+05:30 [INF] Reset guest user to config
2019-02-22T15:15:06.980+05:30 [INF] Starting admin server on :4985
2019-02-22T15:15:06.984+05:30 [INF] Starting server on :4984 …
2019-02-22T15:15:06.988+05:30 [INFO] Using plain authentication for user sync_gateway
2019-02-22T15:15:57.175+05:30 [INF] HTTP: #001: GET /techspin/_session (as GUEST)
2019-02-22T15:15:57.175+05:30 [INF] HTTP+: #001: --> 200 (0.0 ms)
2019-02-22T15:15:57.209+05:30 [INF] HTTP: #002: POST /techspin/_facebook
2019-02-22T15:15:57.209+05:30 [INF] HTTP: #002: --> 404 unknown URL (0.0 ms)

Please help,
Thanks in advance

This 404 unknown URL is returned for the {db}/_facebook URL specifically when the Sync Gateway configuration has not included a “facebook” section.

You will need to add this into your Sync Gateway configuration:

"facebook": {
    "register": false
}

You can change “register” to true depending on desired behaviour.
Docs reference: https://docs.couchbase.com/sync-gateway/2.1/config-properties.html#facebook

Hi bbrks,

I have tried with your suggestion but still, I am getting the same error

the following is my sync_gateway configuration file please tell me if I am doing it correctly

{
 "interface": ":4984",
"adminInterface": ":4985",
"log": ["CRUD", "CRUD+", "HTTP", "HTTP+", "Access", "Cache", "Shadow", "Shadow+", "Changes", "Changes+"],
"databases": {
    "techspin": {
      "server": "http://192.168.1.15:8091",
      "bucket": "default",
      "username": "sync_gateway",
      "password": "password",
      "use_views": true,
      "facebook": {
                    "register": false
                  },
      "sync": `
                function(doc, oldDoc) {
                if (doc.type == "task") {
                  if (!doc.list_id) {
                    throw({forbidden : "items must have a list_id"})
                  }
                  channel("company-list");
                } else if (doc.type == "list") {
                  channel("company-list");
                  if (oldDoc) {
                    var oldOwnerName = oldDoc.owner.substring(oldDoc.owner.indexOf(":")+1);
                    requireUser(oldOwnerName  )
                  }
                  var ownerName = doc.owner.substring(doc.owner.indexOf(":")+1);
                  access(ownerName, "list-"+doc._id);
                  if (Array.isArray(doc.members)) {
                    var memberNames = [];
                    for (var i = doc.members.length - 1; i >= 0; i--) {
                    memberNames.push(doc.members[i].substring(doc.members[i].indexOf(":")+1))
                    };
                    access(memberNames, "list-"+doc._id);
                  }
                } else if (doc.type == "profile") {
                  channel("profiles");
                  var user = doc._id.substring(doc._id.indexOf(":")+1);
                  if (user !== doc.user_id) {
                    throw({forbidden : "profile user_id must match docid"})
                  }
                  requireUser(user);
                  access(user, "profiles"); // TODO this should use roles
                }
              }        `,
      "users": {
          "GUEST": {
              "disabled": false,
              "admin_channels": ["*"]
          }
      }
  }
}
}

Thank you

Hi,

The facebook property is not a database specific option, but needs to be at the top-level of your config. E.g:

{
  // ...
  "facebook": {
    "register": false
  },
  "databases": {
    "...": {
      // ...
    }
  }
}

Thank you bbrks,
Now I am not getting unknown URL error but still, the data is not getting synced from couchbase lite to couchbase.


error log

2019-02-22T16:53:54.627+05:30 [WRN] Using deprecated config option: log. Use logging.console.log_keys 
instead. -- rest.(*ServerConfig).deprecatedConfigLoggingFallback() at config.go:623
2019-02-22T16:53:54.628+05:30 [WRN] Deprecated log key: "CRUD+" found. Changing to: "CRUD". -- 
base.ToLogKey() at log_keys.go:158
2019-02-22T16:53:54.629+05:30 [WRN] Deprecated log key: "Shadow+" found. Changing to: "Shadow". --    
base.ToLogKey() at log_keys.go:158
2019-02-22T16:53:54.629+05:30 [WRN] Deprecated log key: "Changes+" found. Changing to: "Changes". -- 
base.ToLogKey() at log_keys.go:158
2019-02-22T16:53:54.629+05:30 [ERR] No logFilePath configured, and --defaultLogFilePath flag is not set. 
Log files required for product support are not being generated. -- base.(*LoggingConfig).Init() at 
logging_config.go:40
2019-02-22T16:53:54.629+05:30 ==== Couchbase Sync Gateway/2.1.2(2;35fe28e) ====
2019-02-22T16:53:54.630+05:30 [INF] Console LogKeys: [Access Cache Changes CRUD HTTP HTTP+ 
Shadow]
2019-02-22T16:53:54.630+05:30 [INF] Console LogLevel: info
2019-02-22T16:53:54.631+05:30 [INF] Log Redaction Level: none
2019-02-22T16:53:54.631+05:30 [INF] Opening db /techspin as bucket "default", pool "default", server 
<http://192.168.1.15:8091>
2019-02-22T16:53:54.631+05:30 [INF] GoCBCustomSGTranscoder Opening Couchbase database default on 
<http://192.168.1.15:8091> as user "sync_gateway"
2019-02-22T16:53:54.637+05:30 [INF] Successfully opened bucket
2019-02-22T16:53:54.647+05:30 [INF] Design docs for current SG view version (2.1) found.
2019-02-22T16:53:54.648+05:30 [INF] Verifying view availability for bucket default...
2019-02-22T16:53:54.666+05:30 [INF] Views ready for bucket default.
2019-02-22T16:53:54.667+05:30 [INF] Cache: Initializing changes cache with options 
{ChannelCacheOptions:{ChannelCacheMinLength:0 ChannelCacheMaxLength:0 ChannelCacheAge:0s} 
CachePendingSeqMaxWait:5s CachePendingSeqMaxNum:10000 CacheSkippedSeqMaxWait:1h0m0s}
2019-02-22T16:53:54.667+05:30 [INF] Initializing changes cache for database techspin
2019-02-22T16:53:54.754+05:30 [INF]     Reset guest user to config
2019-02-22T16:53:54.756+05:30 [INF] Starting admin server on :4985
 2019-02-22T16:53:54.761+05:30 [INF] Starting server on :4984 ...
 2019-02-22T16:53:54.764+05:30 [INFO] Using plain authentication for user <ud>sync_gateway</ud>
 2019-02-22T16:53:54.824+05:30 [INF] Cache: Received #7 ("_user/")
2019-02-22T16:53:54.824+05:30 [INF] Cache: Initialized cache for channel "*" with options: & 
{ChannelCacheMinLength:50 ChannelCacheMaxLength:500 ChannelCacheAge:1m0s}
2019-02-22T16:53:54.825+05:30 [INF] Cache:     #7 ==> channel "*"
 2019-02-22T16:54:27.855+05:30 [INF] HTTP:  #001: GET /techspin/_session (as GUEST)
2019-02-22T16:54:27.855+05:30 [INF] HTTP+: #001:     --> 200   (0.0 ms)
2019-02-22T16:54:27.880+05:30 [INF] HTTP:  #002: POST /techspin/_facebook (as GUEST)
2019-02-22T16:54:28.114+05:30 [INF] HTTP:  #003: GET /techspin/_session (as GUEST)
2019-02-22T16:54:28.114+05:30 [INF] HTTP+: #003:     --> 200   (0.0 ms)
2019-02-22T16:54:28.144+05:30 [INF] HTTP:  #004: POST /techspin/_facebook (as GUEST)
2019-02-22T16:54:28.499+05:30 [INF] HTTP: #002:     --> 401 Facebook verification server status 400  (619.2 
ms)
2019-02-22T16:54:29.425+05:30 [INF] HTTP: #004:     --> 401 Facebook verification server status 400  
(1280.9 ms).

Thank You

The errors in your logs suggest there’s still a problem authenticating with Facebook. The error messages in the response bodies will likely tell you what’s going wrong with your requests.

2019-02-22T16:54:28.144+05:30 [INF] HTTP:  #004: POST /techspin/_facebook (as GUEST)
2019-02-22T16:54:28.499+05:30 [INF] HTTP: #002:     --> 401 Facebook verification server status 400  (619.2 
ms)
2019-02-22T16:54:29.425+05:30 [INF] HTTP: #004:     --> 401 Facebook verification server status 400  

Are you calling the _session and _facebook endpoints directly yourself? If not, how are you authenticating with Couchbase Lite?

I have no idea, I have not written the sync_gateway connection code
would it be possible to help me if I could share the sync_gateway connection code?

its a 500 lines code

this is part of the code where i think the error is…

function register_token(cb) {
var registerData = {
    remote_url : config.site.syncUrl,
    email : config.user.email,
    access_token : config.user.access_token
}
 coax.post([config.server, "_facebook_token"], registerData, cb)
}



function get_user(cb) {
 var accessToken = '123';
 get_user_info(accessToken, function(err, data) {
 cb(false, data)
 })
   }

function get_user_info(token, cb) {
var data={};
 config.user=null
  cb(false, data)
var uid = window.localStorage.getItem("session_user_id");
 var name = window.localStorage.getItem("session_user_name");
  var token = window.localStorage.getItem("session_token");
 var email = window.localStorage.getItem("session_email_id");
data = {
  id:uid,
  name:name,
  email:email,
  access_token:token
};
cb(false, data)

}

function get_new_token(cb) {
get_user(function(err, data){
config.setUser(data, function(err, ok){
register_token(cb)
})
})
}
function triggerSync(cb, retryCount) {
if (!config.user) {
return log(“no user”)
}
var remote = {
url : config.site.syncUrl,
auth : {facebook : {email : config.user.email}} // why is this email?

},

push = {
    source : appDbName,
    target : remote,
    continuous : true
}, pull = {
    target : appDbName,
    source : remote,
    continuous : true
     },

pushSync = syncManager(config.server, push),
pullSync = syncManager(config.server, pull)
alert(" remote "+remote.url)
log("pushSync", push)

if (typeof retryCount == "undefined") {
    retryCount = 3
}
var challenged = false;
function authChallenge() {
    if (challenged) {return}
    challenged = true;
    pushSync.cancel(function(err, ok) {
        pullSync.cancel(function(err, ok) {
            if (retryCount == 0) {return cb("sync retry limit reached")}
            retryCount--
            get_new_token(function(err, ok) {
              triggerSync(cb, retryCount)
            })
        })
    })
}
pushSync.on("auth-challenge", authChallenge)
pullSync.on("auth-challenge", authChallenge)

pushSync.on("error", function(err){
    if (challenged) {return}
    cb(err)
})
pushSync.on("connected", function(){
    pullSync.start()
})
pullSync.on("error", function(err){
    if (challenged) {return}
    cb(err)
})
pullSync.on("connected", function(){
    cb()
})
// setTimeout(function(){
    pushSync.start()
// }, 10000)
}

Thanks in advance

I can’t really help beyond a cursory glance, but have you got this access token set correctly?

Again, looking at the response body will help you determine what’s wrong with this.
It looks like something going wrong between your app and Facebook before you send the authentication request to Sync Gateway.

Hi bbrks,

Thank you for your response,

I am trying to get this app work locally,

So the mobile, sync_ gateway, and couchbase server are on the same network,

Is there a way that I could get it to work without a facebook authentication, and return a token for it to work…

Thank you.

Yes you can use Sync Gateway’s built-in users to provide authentication instead of using a third-party.

This is all described in the documentation: https://docs.couchbase.com/sync-gateway/2.1/authorizing-users.html#authorizing-users

1 Like

Thank you for your support,
I was able to make it work.

1 Like