Creating Multiple Elements In One POST Request using TWC API

MagicDraw OpenAPI, scripting related questions and discussions

Moderator: Moderators

Creating Multiple Elements In One POST Request using TWC API

Postby alan.j.constantino@lmco.com » Mon Mar 13, 2023 1:24 pm

Hello!

I have been utilizing the OSMC TWC Rest API (https://osmc.nomagic.com/2021xr2/swagger/index.html) to create/read/update/delete elements.

My goal is to create a class, within that class create several attributes, and each of those attributes will have a value associated with them.

I'm able to do this but it seems that TWC takes forever to process the request and when you have to generate a lot of classes (80+) with each of them having 10+ attributes and values, it can take a really long time to generate each one.

Right now I'm creating the class first, then once I have that, create the attributes, then I create the values. Since each element relies on the ID of the previous, I have to create them in order at least from how I understand the API.

So I wanted to know if it would be possible to create a class, its attributes and its values within one POST request perhaps like so:
{
"@type": "uml:Class",
"kerml:esiData": {
"name": "MyCustomClass",
"owningPackage": {"@id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"},
"attributes": {
{
"name": "MyFirstAttribute",
"value": "MyValue",
"owningClass": {"@id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
},
{
"name": "MySecondAttribute",
"value": "MySecondValue",
"owningClass": {"@id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
},
.
.
.
.
}
},
"kerml:nsURI": "http://www.nomagic.com/magicdraw/UML/2.5.1.1"
}

I'm aware that the above payload is not valid (at least the "attributes" portion) but I just need to know if something like that would even be possible? Or am I simply stuck having to create each element sequentially (i.e. creating the class first, creating the attribute next and attaching it to the class, and creating the value of the attribute and attaching it to the attribute).

Furthermore, if the latter is the case, is there any way to speed up the responses from the TWC server? Currently it seems to take forever for the TWC server to process all the POST requests I send it.

Any help, suggestions, or resources are highly appreciated!
alan.j.constantino@lmco.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:1
Joined: Mon Mar 13, 2023 1:06 pm

Re: Creating Multiple Elements In One POST Request using TWC API

Postby ramyar.jahani14256@gmail.com » Mon Apr 24, 2023 11:07 pm

It is not possible to create a class, its attributes, and values within a single POST request in the OSMC TWC Rest API. You will have to create each element sequentially, creating the class first, then creating the attributes, and finally creating the values. The API requires each element to have a unique ID and to be created in a specific order.
As for speeding up the responses from the TWC server, you could try optimizing your requests by minimizing the amount of data you send and receive. You could also consider using batch requests to send multiple requests in a single HTTP call, which can significantly reduce the overhead associated with making multiple requests. Additionally, you may want to consider reaching out to the OSMC TWC Rest API support team for more assistance in optimizing your requests. LandstarOnline
ramyar.jahani14256@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 1
Posts Rating:1
Joined: Thu Nov 24, 2022 12:01 am


Return to Programmatic Extendibility

Who is online

Users browsing this forum: No registered users and 0 guests