CURL Command CouchDB Replication - Invalid JSON

I run the following line in curl trying to install couchdb replication:

curl -X POST -d '{"source":"http://user: password@siteA.com :5984/main","target":"main"}' -H 'Content-Type: application/json' http://user: password@siteB.com /_replicate 

He continues to return the following error:

 {"error":"bad_request","reason":"invalid UTF-8 JSON"} 

As far as I can tell, JSON seems valid. Any ideas?

I also use Powershell.

+4
source share
4 answers

This has happened many times for me. PowerShell parser (who knows why) remove quotes in json.

Thus, it sends it to curl as '{source: http: // user: password@siteA.com : 5984 / main, target: main}' You need to call it like this:

 curl -X POST -d '{"""source""":"""http://user: password@siteA.com :5984/main""","""target""":"""main"""}' -H 'Content-Type: application/json' http://user: password@siteB.com /_replicate 

See the http://pscx.codeplex.com/ module. EchoArgs can help detect such problems.

+7
source

Looking at the CouchDB wiki, I found this one that may be useful to solve your problem. Basically under Windows, you need to avoid special characters or write JSON to a file and use it from CLI curl.

+2
source

I had problems with curl and PowerShell before - my resolution was to call it from a batch file (the output is placed in a PowerShell variable) ... thought this could be due to the way the arguments passed for the wave were misinterpreted - I never got to the end, since it worked ...

maybe this could help http://huddledmasses.org/the-problem-with-calling-legacy-or-native-apps-from-powershell/

0
source

Check out this powershell module for CouchDB and run this:

 New-CouchDBReplication -SourceServer localhost -TargetServer server1 -SourceDatabase test -TargetDatabase test_replica -Continuous -Authorization "admin:password" 
0
source

All Articles