{"error":"bad_request","reason":"attachments not supported in Couchbase"}

hi,
i try to use lcb_make_http_request to get data from view, it return LCB_SUCCESS but the response is :
{"error":"bad_request","reason":"attachments not supported in Couchbase"}
what this mean?
I run the uri in web browser, i can get result
host:8092/bucketname/_design/dev_prod/_view/view_name?startkey="123456789"&limit=10

similar question has been asked, but no answer yet:
http://www.couchbase.com/forums/thread/python-client-delete-design-doc

thanks!

2 Answers

« Back to question.

hi, avsej:
couple questions regarding the c code:
1. i use data_callback instead of complete_callback

2. i use LCB_HTTP_METHOD_GET not POST or PUT, because i intend to get something from view
so cmd.v.v0.body is empty, cmd.v.v0.nbody == 0,

3. should we assign full path to cmd.v.v0.path ? like:
string uri = host + ":" + VIEW_PORT + "/" + _bucketname + "/_design/"+_designdocname + "/_view/" + _viewname +"?key="+ "\"" + _key +"\"";

my code:

lcb_error_t err;
lcb_http_cmd_t cmd;
string uri;
uri	= host + ":" + VIEW_PORT + "/" + _bucketname + "/_design/"+_designdocname + "/_view/" + _viewname +"?startkey="+ "\"" + _key +"\"";
 
if(_pageId > 1)
{
		uri	+= "&startkey_docid=" + _lastDocID;
		uri += "&skip=1";
}
	if(_limit > 0)
	{
		stringstream ss;
		ss << _limit;
		uri += "&limit=" + ss.str();
	}
	std::cout<<"uri:"<<uri<<std::endl;
	size_t nbytes = 0;
	const char * bytes = _postData.c_str();
    if (bytes) {
        nbytes = strlen(bytes);
    }
	cmd.version = 0;
    cmd.v.v0.path = uri.c_str();
    cmd.v.v0.npath = strlen(uri.c_str());
    cmd.v.v0.body = bytes;
    cmd.v.v0.nbody = nbytes;
    cmd.v.v0.method = bytes ? LCB_HTTP_METHOD_POST : LCB_HTTP_METHOD_GET;
    cmd.v.v0.chunked = true;
    cmd.v.v0.content_type = "application/json";
	err = lcb_make_http_request(instance, (void *)this, LCB_HTTP_TYPE_VIEW, &cmd, NULL);
	if (err != LCB_SUCCESS) {
        fprintf(stderr, "Failed to get view by key: %s\n",
                lcb_strerror(NULL, err));
        return false;
    }
	lcb_wait(instance);
	_response = outResponse;
	return true;	
static void data_callback(lcb_http_request_t request,
                          lcb_t instance,
                          const void *cookie,
                          lcb_error_t error,
                          const lcb_http_resp_t *resp)
{
    if (error != LCB_SUCCESS) {
        return;
    }
    CouchbaseHandler *couchbaseHandler;
    couchbaseHandler 
	= const_cast<CouchbaseHandler *>(reinterpret_cast<const CouchbaseHandler *>(cookie));
 
    string response;
	if(resp->v.v0.bytes)
	{
		response.assign((const char*)resp->v.v0.bytes,resp->v.v0.nbytes);
		couchbaseHandler->setOutResponse(response);
	}
 
}

note that i assigned outResponse with response from view in data_callback.

thanks!

« Back to question.

I get the same thing following the REST API to a T to create a new view. Even though the documentation says to use an attachment. My guess is the documentation is wrong.

Here is an example of my restful call that fails

curl -X PUT -H 'Content-Type: application/json' http://user:password@localhost:8092/bucket/_design/name/newView -d @newView.ddoc

And the response:
{"error":"bad_request","reason":"attachments not supported in Couchbase"}

I've found a lot of the REST API documentation to be completely inaccurate or just doesn't work, which makes it rather difficult to extend and incorporate couchbase into any environment.