# Create stack from catalog using API

**URL:** <https://forums.suse.com/t/create-stack-from-catalog-using-api/6572>\
**Category:** Rancher 1.x\
**Created:** [June 7, 2017, 3:21pm UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572 "2017-06-07T15:21:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nosmoht](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/nosmoht/32/2747_2.png) [@Nosmoht](https://forums.suse.com/u/Nosmoht)\
**Post date:** [June 7, 2017, 3:21pm UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572/1 "2017-06-07T15:21:19Z")

</div>

Hi all,

how to create a catalog stack using API?

I would like to deploy Rancher NFS directly after setting up the system using API but can’t find how to do that.  
Could someone please help?

---

<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:** [June 8, 2017, 12:33am UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572/2 "2017-06-08T00:33:25Z")

</div>

There is not a specific API for this; the UI gets the compose files from the catalog (`/v1-catalog/templates/` , find the specific catalog/templateversion you want) and then sends it to create stack (`POST /v2-beta/projects/1a5/stacks` with those file contents as the compose files. Detecting it as a catalog item and the upgrade checking and all that is done by setting the stack’s `externalId` to `catalog://` + the ID of the templateVersion.

---

<div class="post-metadata">

**Author:** ![Nosmoht](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/nosmoht/32/2747_2.png) [@Nosmoht](https://forums.suse.com/u/Nosmoht)\
**Post date:** [June 12, 2017, 4:14pm UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572/3 "2017-06-12T16:14:01Z")

</div>

Thanks Vincent,

it works like a charm. Just wondering why API endpoint is v1-catalog. Are there any plans to move it to v2-beta?

---

<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:** [June 12, 2017, 9:17pm UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572/4 "2017-06-12T21:17:07Z")

</div>

There are several things that are run as separate microservices and not part of cattle itself, each have their own version number and suffix. `/v1-auth`, `/v1-webhooks`, `/v1-telemetry` (if enabled), etc.

---

<div class="post-metadata">

**Author:** ![ranjith](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@ranjith](https://forums.suse.com/u/ranjith)\
**Post date:** [February 19, 2018, 2:31pm UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572/5 "2018-02-19T14:31:49Z")

</div>

We are trying to use the above mentioned Method to create stack from catalog.

When we try to send the files that we get from /v1-catalog/templateversions for the POST of /v2-beta/projects/1a5/stacks we get the following response.

{“id”:“7d414b26-d7dc-4f76-8259-04e4bd66ce14”,“type”:“error”,“links”:{},“actions”:{},“status”:400,“code”:“InvalidBodyContent”,“message”:“InvalidBodyContent”,“detail”:null,“baseType”:“error”}

How to debug this kind of response. Not much information available

---

<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:** [February 20, 2018, 5:35pm UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572/6 "2018-02-20T17:35:38Z")

</div>

Can you post the actual request body & headers?

---

<div class="post-metadata">

**Author:** ![ranjith](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@ranjith](https://forums.suse.com/u/ranjith)\
**Post date:** [February 21, 2018, 4:48am UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572/7 "2018-02-21T04:48:43Z")

</div>

I am trying to integrate Create catalog API using python requests…

**Code:**

```
import requests, json

 /* Getting the docker-compose and rancher-compose content from mysql catalog */

resp = requests.get('http://x.x.x.x:x/v1-catalog/templateversions/community:mysql:0', auth=('E492D67A8E8C221CCABC', 'xb6qsZQFegcydwmvX4axvnnXLAXi4eMoMuzFmYos'), headers={"Content-Type":"application/json"})
var = json.loads(resp.text)

docker_compose = var['files']['docker-compose.yml.tpl']
rancher_compose = var['files']['rancher-compose.yml']

/* Creating the payload(request body) for creating stack */

post_data = {"system":False,"type":"stack","name":"mysql","startOnCreate":True,"environment":{"mysql_lb_port":"3306","mysql_root_password":"next","mysql_image":"mysql:latest","mysql_database":"","mysql_user":"","mysql_password":"","mysql_allow_empty_password":"no","mysql_random_root_password":"no","mysql_onetime_password":"no"},"dockerCompose":docker_compose,"rancherCompose":rancher_compose,"externalId":"catalog://community:mysql:0"}

 /* Catalog create post request */

data = requests.post('http://x.x.x.x:x/v2-beta/projects/1a5/stacks', auth=('E492D67A8E8C221CCABC', 'xb6qsZQFegcydwmvX4axvnnXLAXi4eMoMuzFmYos'), headers={"Content-Type":"application/json"}, data=post_data)
print data.text

```

**Output (Error):**

{“id”:“7d414b26-d7dc-4f76-8259-04e4bd66ce14”,“type”:“error”,“links”:{},“actions”:{},“status”:400,“code”:“InvalidBodyContent”,“message”:“InvalidBodyContent”,“detail”:null,“baseType”:“error”}

How to debug this kind of response. Not much information available.

---

<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:** [February 21, 2018, 5:26am UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572/8 "2018-02-21T05:26:45Z")

</div>

That looks like you’re trying to post the raw dictionary instead of encoding it to a JSON string. So you’re probably sending whatever the “toString” of a dictionary is, which isn’t JSON and the server has no idea how to parse it.

---

<div class="post-metadata">

**Author:** ![ranjith](https://avatars.discourse-cdn.com/v4/letter/r/8797f3/32.png) [@ranjith](https://forums.suse.com/u/ranjith)\
**Post date:** [February 21, 2018, 6:23am UTC](https://forums.suse.com/t/create-stack-from-catalog-using-api/6572/9 "2018-02-21T06:23:03Z")

</div>

Thanks @vincent. Tried your solution. Its working fine now.
