# Post data to create new stack

**URL:** <https://forums.suse.com/t/post-data-to-create-new-stack/5117>\
**Category:** Rancher 1.x\
**Created:** [January 6, 2017, 10:34pm UTC](https://forums.suse.com/t/post-data-to-create-new-stack/5117 "2017-01-06T22:34:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mostafa](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/mostafa/32/1989_2.png) [@mostafa](https://forums.suse.com/u/mostafa)\
**Post date:** [January 6, 2017, 10:34pm UTC](https://forums.suse.com/t/post-data-to-create-new-stack/5117/1 "2017-01-06T22:34:21Z")

</div>

Just came through the following question about [how to create a stack using catalog api](http://forums.suse.com/t/use-api-to-start-new-container-from-catalog/3084/) and I have tried what @vincent [suggested](http://forums.suse.com/t/use-api-to-start-new-container-from-catalog/3084/3?u=mostafa) but I am facing a problem with the `POST` step.

Note: I am using `v2-beta` api so I am doing the `POST` request against this URL: `/v2-beta/projects/<projectID>/stacks` and previously I tried the v1 api `/v1/projects/<projectID>/environments` which have the same result.

The data i sent:

```auto
 {'environment': {'public_port': 8035}, 'rancherCompose': u'.catalog:\n name: "Wordpress"\n version: "v0.1-educaas1"\n description: "Blog tool, publishing platform and CMS"\n uuid: Wordpress-0\n minimum_rancher_version: v0.51.0\n questions: \n - variable: public_port\n description: "public port to access the wordpress site"\n label: "Public Port"\n required: true\n default: "80"\n type: "int"\n\n\nwordpress:\n', 'name': 'API tester', 'dockerCompose': u'wordpress:\n image: wordpress\n links:\n - db:mysql\n ports:\n - ${public_port}:80\n\ndb:\n image: mariadb\n environment:\n MYSQL_ROOT_PASSWORD: example\n'}

```

And the response I got:

```auto
{"id":"da2a00ba-3ac3-447a-9581-c9920a6a0588",
 "type":"error","links":{},"actions: {},"status":422,"code":"InvalidFormat",
 "message":null,"detail":null,"fieldName":"environment","baseType":"error"}

```

The response is telling me that there is an error with the `datatype` of `environment` which I pass it as a `dict` after debugging a little I noticed that the Rancher API is seeing the value as string like this:

```auto
{
  "environment": "public_port",
  "name": "API tester",
  "rancherCompose": ".catalog:\n name: \"Wordpress\"\n version: \"v0.1-educaas1\"\n description: \"Blog tool, publishing platform and CMS\"\n uuid: Wordpress-0\n minimum_rancher_version: v0.51.0\n questions: \n - variable: public_port\n description: \"public port to access the wordpress site\"\n label: \"Public Port\"\n required: true\n default: \"80\"\n type: \"int\"\n\n\nwordpress:\n",
  "dockerCompose": "wordpress:\n image: wordpress\n links:\n - db:mysql\n ports:\n - ${public_port}:80\n\ndb:\n image: mariadb\n environment:\n MYSQL_ROOT_PASSWORD: example\n"
}

```

I don’t know why the value changed even if i printed the payload before passing it to the `POST` request to make sure that I am passing the correct format.  
Rancher version is 1.2.1

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [January 6, 2017, 11:45pm UTC](https://forums.suse.com/t/post-data-to-create-new-stack/5117/2 "2017-01-06T23:45:39Z")

</div>

I don’t know what you’re using to serialize the JSON object but seems like it doesn’t support nested objects or something… The audit log is the raw body that was received so it must be getting sent wrong.

---

<div class="post-metadata">

**Author:** ![mostafa](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/mostafa/32/1989_2.png) [@mostafa](https://forums.suse.com/u/mostafa)\
**Post date:** [January 7, 2017, 12:16am UTC](https://forums.suse.com/t/post-data-to-create-new-stack/5117/3 "2017-01-07T00:16:38Z")

</div>

Thanks for pointing me in the right direction ! I made it work I was serializing the JSON in a wrong way.

I have added `startOnCreate` in order to start the service immediately. Is there any required value should I pass it other than that ?

---

<div class="post-metadata">

**Author:** ![Aravind](https://avatars.discourse-cdn.com/v4/letter/a/e8c25b/32.png) [@Aravind](https://forums.suse.com/u/Aravind)\
**Post date:** [January 30, 2018, 4:22am UTC](https://forums.suse.com/t/post-data-to-create-new-stack/5117/4 "2018-01-30T04:22:07Z")

</div>

I got this error while creating a stack.

I tried:

curl -u “key:key” -X POST -d ‘{“name”:“HGDGGG”}’ ‘http://server\_ip:8080/v2-beta/stack’

Response:

{“id”:“7e795f30-f5f5-4f3d-add0-109e970403f6”,“type”:“error”,“links”:{},“actions”:{},“status”:405,“code”:“Method not allowed”,“message”:“Method not allowed”,“detail”:null,“baseType”:“error”}

What is the issue here and how to resolve it??

@discobot @vincent

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [January 30, 2018, 8:07am UTC](https://forums.suse.com/t/post-data-to-create-new-stack/5117/5 "2018-01-30T08:07:21Z")

</div>

Stacks belong to an environment (project), you are using a user API key which has access to many projects so you need to post to `/v2-beta/projects/your_project_id/stacks`.
