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

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

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:

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”

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

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:

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

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

1 Like