# Create rancher secret via API

**URL:** <https://forums.suse.com/t/create-rancher-secret-via-api/13456>\
**Category:** SUSE Rancher Prime\
**Created:** [February 26, 2019, 11:41am UTC](https://forums.suse.com/t/create-rancher-secret-via-api/13456 "2019-02-26T11:41:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Peacock](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/andrew_peacock/32/3724_2.png) [@Andrew\_Peacock](https://forums.suse.com/u/Andrew_Peacock)\
**Post date:** [February 26, 2019, 11:41am UTC](https://forums.suse.com/t/create-rancher-secret-via-api/13456/1 "2019-02-26T11:41:24Z")

</div>

Hi,  
I’m trying to create a rancher secret for all namespaces, via the API (I’m pretty sure you can’t do this via kubectl or rancher CLIs - please let me know if that’s incorrect!).

So far, I’ve got:

curl --insecure -u token-:   
–data “data.param1=value1” --data “data.param2=value2” --data “name=global-variable2”   
“https:///v3/projects/c-j7dsx:p-98c6s/secrets”

However, I’ve tried a few methods of getting the data into the secret, with no joy. The secret resource is created, but when I do 'kubectl get -o yaml", I get the following:

apiVersion: v1  
kind: Secret  
metadata:  
annotations:  
[field.cattle.io/creatorId:](http://field.cattle.io/creatorId:) user-q2crt  
[field.cattle.io/projectId:](http://field.cattle.io/projectId:) c-j7dsx:p-98c6s  
[lifecycle.cattle.io/create.secretsController\_c-j7dsx:](http://lifecycle.cattle.io/create.secretsController_c-j7dsx:) “true”  
[secret.user.cattle.io/secret:](http://secret.user.cattle.io/secret:) “true”  
creationTimestamp: 2019-02-26T11:38:02Z  
name: global-variable2  
namespace: default  
resourceVersion: “12185”  
selfLink: /api/v1/namespaces/default/secrets/global-variable2  
uid: f9491dac-39ba-11e9-b0bd-baeea5553cb1  
type: Opaque

As you can see, there is no data there. Can anyone help?

Thanks in advance,  
Andy

---

<div class="post-metadata">

**Author:** ![Andrew\_Peacock](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/andrew_peacock/32/3724_2.png) [@Andrew\_Peacock](https://forums.suse.com/u/Andrew_Peacock)\
**Post date:** [February 26, 2019, 4:14pm UTC](https://forums.suse.com/t/create-rancher-secret-via-api/13456/2 "2019-02-26T16:14:16Z")

</div>

OK, I got there in the end:

curl --insecure -u   
–header “Content-Type: application/json”   
–request POST   
–data ‘{“name”:“global-variable10”, “data”: {“test”:“dmFsdWUxCg==”, “test2”:“YmFuYW5hcwo=”}}’   
“https:///v3/projects/c-j7dsx:p-98c6s/secrets”
