How to create a new folder via curl?

Hello,

I managed to create a secret inside an existing folder using curl:

sh(‘curl -H “X-Vault-Token: myToken” -H “Content-Type: application/json” -X POST -d '{“data”:{“APIUsername”:“uid123”}}' https://vault-address.de/v1/jenkins-test-instance1/data/folder’)

This creates the new secret key value pair: “APIUsername” and “uid123” inside the already existing “jenkins-test-instance1” and “folder” folders.

But how could I create a secret inside new folders?

For example:

sh(‘curl -H “X-Vault-Token: myToken” -H “Content-Type: application/json” -X POST -d '{“data”:{“APIUsername”:“uid123”}}' https://vault-address.de/v1/jenkins-test-instance2/data/folder2’)

This should add a new folder “jenkins-test-instance2”, “folder2” , and inside “folder2” create the secret.

When trying anything I always get:
{“errors”:[“no handler for route ‘jenkins-test-instance2/data/folder2’”]}

Thank you!

jenkins-test-instance1 is your kv-v2 secret engine mount point.

Normally that’s mounted on secret which would yield a secret API path /v1/secret/data/:path

Using the same logic, if you want to create another secret for the same engine mount, then you should use
/v1/jenkins-test-instance1/data/:path

Additionally you may enable a new secrets engine instance at a different path using
vault secrets enable kv-v2 -path <new_path>