How to pass session for target to http://localhost:4985/_replicate

query

#1

Using sync gateway 2.0 what is the way to trigger a replication from one sync gateway to another target sync gate way passing in session information for the target sync gateway?

We are triggering replication by calling the replicate api (docs). We create a session for a user on the target sync gateway by calling the session api (docs). This returns a session in the Set-Cookie header which we can extract. Now we want to trigger a replication from our local sync gateway to this target sync gateway and have it use this session. How can we do this?

From the documentation, it mentions that it is possible to pass in header information by setting the target to a “object” instead of a “string”. However this fails with a bad request error:

HTTP Request

POST /_replicate HTTP/1.1
Host: localhost
Content-Type: application/json
cache-control: no-cache
{
	"replication_id": "myReplication",
	"source": "http://localhost:4984/mydb",
	"target": { "url" : "http://remotehost:4984/targetdb", "headers" : { "Cookie": "SyncGatewaySession=******" } },
	"continuous": false,
	"cancel": false,
	"async": true,
	"changes_feed_limit": 200,
	"filter": "sync_gateway/bychannel",
	"query_params": ["c1"]
}

HTTP Response

HTTP/1.1 400 Bad Request
Server: Couchbase Sync Gateway/2.0.0
Date: Thu, 11 Oct 2018 21:09:56 GMT
Content-Type: application/json
Content-Length: 143
{
    "error": "Bad Request",
    "reason": "Invalid JSON: \"json: cannot unmarshal object into Go struct field ReplicationConfig.target of type string\""
}

#2

@traun ,

This is an interesting idea.
also where/how would you store it in. Probably have to extend special sg-replicate _sync:user:*** and store it in there.