400 error when making an http request


I’m getting a “bad request” when trying to do this against Couchbase 6.6

                            string postData= "name=activities&bucketType=ephemeral&ramQuotaMB=4364&evictionPolicy=nruEviction&replicaIndex=0&flushEnabled=1";
                            ASCIIEncoding encoding = new ASCIIEncoding();
                            byte[] data = encoding.GetBytes(postData);

                            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("");
                            request.PreAuthenticate = true;
                            request.Credentials = new NetworkCredential("administrator", "mypassword");                            
                            request.Method = "POST";
                            request.ContentType = "application/x-www-form-urlencoded";
                            request.ContentLength = data.Length;
                            using (Stream stream = request.GetRequestStream())
                                stream.Write(data, 0, data.Length);
                            var response = (HttpWebResponse)request.GetResponse();



It would be helpful to know the content of the “bad request” response. There is typically an error message in that response that can point you in the right direction. I like to use Postman to prove out HTTP requests before trying them in C#.

When I ran this request in Postman, I got the response:

	"errors": {
		"replicaIndex": "replicaIndex not supported for ephemeral buckets"
	"summaries": {
		... snip ...

So I took out replicaIndex and then it executed fine (in Postman and in C#):

string postData = "name=activities&bucketType=ephemeral&ramQuotaMB=4364&evictionPolicy=nruEviction&flushEnabled=1";

I assumed I was getting it because of a wrong content-type or something.
Once I was able to reach the response by catching the exception I saw the problem.

1 Like