# Is it possible to export/import custom smart rest templates via rest/http

**URL:** <https://community.cumulocity.com/t/is-it-possible-to-export-import-custom-smart-rest-templates-via-rest-http/961>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [September 13, 2022, 8:41am UTC](https://community.cumulocity.com/t/is-it-possible-to-export-import-custom-smart-rest-templates-via-rest-http/961 "2022-09-13T08:41:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lorn\_Kjewlsvar](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/lorn_kjewlsvar/32/7097_2.png) [@Lorn\_Kjewlsvar](https://community.cumulocity.com/u/Lorn_Kjewlsvar)\
**Post date:** [September 13, 2022, 8:41am UTC](https://community.cumulocity.com/t/is-it-possible-to-export-import-custom-smart-rest-templates-via-rest-http/961/1 "2022-09-13T08:41:12Z")

</div>

Hello cumulocity community,

#### What product/components do you use and which version/fix level are you on?

cumulocity iot platform 1011.0.12, smart rest templates 2.0

#### Is your question related to the free trial, or to a production (customer) instance?

customer instance

#### What are you trying to achieve? Please describe it in detail.

We want to be able to export settings and configurations from a super tenant and import them on any sub tenant. We have created multiple scripts to export and import configurations via curl. For smart rest templates I only found the export/import function in the device management app, but no http/rest endpoints for that. I also know it is possible to register new smart rest templates via rest. But we also need them to be exported via rest.

greetings and thanks in advance

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [September 13, 2022, 9:28am UTC](https://community.cumulocity.com/t/is-it-possible-to-export-import-custom-smart-rest-templates-via-rest-http/961/2 "2022-09-13T09:28:58Z")

</div>

Hi Lorn,

the export functions seems to be an UI-only functionality.  
The good news is that it can be easily exported and imported using the inventory API:

```auto
GET {{url}}/inventory/managedObjects?type=c8y_SmartRest2Template

```

will give you all smart rest templates.  
To import them you need to remove all properties but to keep “name”, “type”, “\_\_externalId” and “com\_cumulocity\_model\_smartrest\_csv\_CsvSmartRestTemplate”

```auto
POST {url}}/inventory/managedObjects
Body:
{
  "name": "customEvent",
  "type": "c8y_SmartRest2Template",
  "com_cumulocity_model_smartrest_csv_CsvSmartRestTemplate": {
    "requestTemplates": [],
    "responseTemplates": []
  },
  "__externalId": "test123"
}

```

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [September 13, 2022, 10:02am UTC](https://community.cumulocity.com/t/is-it-possible-to-export-import-custom-smart-rest-templates-via-rest-http/961/3 "2022-09-13T10:02:25Z")

</div>

Note that you also have to assign the externalId of type `c8y_SmartRest2DeviceIdentifier` to the newly created managedObject.  
So after the POST request to the inventory from above you would have to create the externalId for that managedObject:

```auto
POST {{url}}/identity/globalIds/{{idOfCreatedManagedObject}}/externalIds
Body:
{
	"externalId": "<theValueFrom__externalIdField>",
    "type": "c8y_SmartRest2DeviceIdentifier"
}

```

---

<div class="post-metadata">

**Author:** ![Lorn\_Kjewlsvar](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/lorn_kjewlsvar/32/7097_2.png) [@Lorn\_Kjewlsvar](https://community.cumulocity.com/u/Lorn_Kjewlsvar)\
**Post date:** [September 16, 2022, 7:01am UTC](https://community.cumulocity.com/t/is-it-possible-to-export-import-custom-smart-rest-templates-via-rest-http/961/4 "2022-09-16T07:01:16Z")

</div>

Hello Stefan and hello Tristan,

thank you for your answers. I followed the first steps to get the information via  
`GET {{url}}/inventory/managedObjects?type=c8y_SmartRest2Template`

I could not find any `__externalId` property in the data I received. Can you clearify if I really need the externalId and how to get it?

I sent the data per Post request to the inventory without specifying the externalId. Under Device Management \> Device types \> SmartREST Templates I saw that the templates where successfully imported.

Edit: I saw that the ID of the SmartREST template was not present. It was neccessary to set a POST request against `POST {{url}}/identity/globalIds/{{idOfCreatedManagedObject}}/externalIds`.

greetings

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [March 15, 2023, 7:02am UTC](https://community.cumulocity.com/t/is-it-possible-to-export-import-custom-smart-rest-templates-via-rest-http/961/5 "2023-03-15T07:02:03Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
