Can't create a db with admin API with curl

I tried to revive another thread of the same topic but I got crickets, so re-posting as a new topic.

I can’t create a db/bucket via the admin API. Looking at the headers, I’m not getting a 401 error, but a 502 bad gateway (which seems odd, since it can talk for many operations.

Here’s the command I’m trying:

curl -v -X PUT -H "Content-Type: application/json" \
http://localhost:4985/userdata/ \
-d '{"server":"http://couchbase:8091", "bucket":"userdata", "username":"<name>", "password": "<pwd>", "users":{}}'

And the relevant responses I get are:

Auth: Attempting credential authentication http://couchbase:8091
Error opening bucket userdata: no access

It seems like it’s trying to open an existing bucket ‘userdata’?

(As an aside, I’m not sure I understand the distinction between a database and a bucket, can a db have more than one bucket? If so, how would you specify in the sgw API syntax?)

Aside #2:

I’ve created two buckets via the couch admin panel. I can list them with the API ‘/_all_dbs’ and I’m able to put and get docs from them. So, that seems to be working, anyway.

Would like to not have to go into the UI to provision the db with the two buckets (and for that matter, the admin/adminpassword) if there’s a way to do that.

@rickbsgu Hi!
Buckets are a concept on the Couchbase Server side whereas a ‘database’ is on the Sync Gateway side. A Sync Gateway database then connects to one of these buckets as a Couchbase Server user and manipulates the data, in the same way that an SDK client would connect to a Couchbase Server bucket.
Therefore, when you try to create a Sync Gateway database without a Couchbase Server bucket it gives the error you are seeing as it is unable to communicate with the non-existent bucket. You must first create the bucket on the Couchbase Server side before attempting to connect to it with Sync Gateway.
It is possible to create a Couchbase Server bucket without visiting the Couchbase Server UI by using either the Couchbase CLI tool or via the REST API. This is covered in the below linked documentation:
CLI Tool: