Adding additional rows to a category using the Content Server Rest API

Looking at the included screenshot one can see plus signs to the right which is use to add addition rows for the category.

How can I use the API to add these rows instead? I.e. which API and perhaps an example if not included in the API description.

Best Answer

  • appuq
    appuq Member
    edited November 4 #2 Answer ✓

    The REST API can only add rows to a Category applied to an object, not the Category subtype=131 itself. Therefore, the screenshot use case is not clear to me.

    The term in the Content Server is MVA(Multi-Valued Attribute). Internally even if the category: Attribute shows a single value it is stored something like catid_versionid_attributeid={"value", "value2"} etc

    {"category_id":9830,"9830_2":"new value"}

    it is akin to saying apply the category called 9830 to its latest category version(implied)

    Go and apply "new value" to the attributeid=2

    (?func=attributes.dump is a useful RH, or select * from CatRegionMap

    So the payload in that fake body you remember from last time will go as

    PUT for a Category Update POST if the Category is not present
    api/v2/nodes/212166/categories/212936
    212166 is the Document Object where the Category 212936 is being applied
    
    body: {
    "212936_2": "Appu",
    "212936_3": [
    "my value1",
    "my value2",
    "my value 3",
    "my value4"
    ] }

    the example in the documentation points to a Set and MVA

    POST is when you want to do it the first time
    api/v1/nodes/212717/categories/ the api is v1 I think
    
    {
    "id": 212717,
    "category_id": 212936,
    "212936_2": "1",
    "212936_3": [
    "2",
    "3",
    "4"
    ]
    } Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="body"

    {"id":212717,"category_id":212936,"212936_2":"1","212936_3":["2","3","4"]}

    ------WebKitFormBoundary7MA4YWxkTrZu0gW--

Answers

  • appuq
    appuq Member
    edited November 4 #3 Answer ✓

    The REST API can only add rows to a Category applied to an object, not the Category subtype=131 itself. Therefore, the screenshot use case is not clear to me.

    The term in the Content Server is MVA(Multi-Valued Attribute). Internally even if the category: Attribute shows a single value it is stored something like catid_versionid_attributeid={"value", "value2"} etc

    {"category_id":9830,"9830_2":"new value"}

    it is akin to saying apply the category called 9830 to its latest category version(implied)

    Go and apply "new value" to the attributeid=2

    (?func=attributes.dump is a useful RH, or select * from CatRegionMap

    So the payload in that fake body you remember from last time will go as

    PUT for a Category Update POST if the Category is not present
    api/v2/nodes/212166/categories/212936
    212166 is the Document Object where the Category 212936 is being applied
    
    body: {
    "212936_2": "Appu",
    "212936_3": [
    "my value1",
    "my value2",
    "my value 3",
    "my value4"
    ] }

    the example in the documentation points to a Set and MVA

    POST is when you want to do it the first time
    api/v1/nodes/212717/categories/ the api is v1 I think
    
    {
    "id": 212717,
    "category_id": 212936,
    "212936_2": "1",
    "212936_3": [
    "2",
    "3",
    "4"
    ]
    } Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="body"

    {"id":212717,"category_id":212936,"212936_2":"1","212936_3":["2","3","4"]}

    ------WebKitFormBoundary7MA4YWxkTrZu0gW--

  • Perfect, that works. Adding the array was what I was lacking. Thank you!

  • You may want to look at the payload using Chrome or Edge network tools and you will be able to see the payload yourself :)

    Here is for a novice.

    1. Go to the action you want to create your code or try to understand OT's swagger(terse) documentation.
    2. An example is showing how to add an MVA
    3. Make sure you are on smartui
    4. Push the F12(Developer Tools) reload page if needed and clean the network tab
    5. Do the thing that you intended.

    Click headers to see the REST API call

  • The normal thing when creating an integration is that you are working on the server side. But perhaps you imply that one should use Postman or similar for above?

    The example in swagger/API specification, related to the array input, is of a little bit different model but understanding how to use it above makes it easier to understand that example. Though, one would need to play around with it a bit to understand it fully I believe. Though 2, that is not the model I need.

    But all is good and it works.

  • appuq
    appuq Member
    edited November 5 #7

    Unfortunately, I find working in OT programming examples very difficult that is also probably because I started working with this product about 25 years ago, and while things have greatly improved OT does not have good quality fully worked examples that are very terse if you ask me. BTW REST is the easiest of things to debug because it goes through a webserver:)

    I wrote this on my blog a few years back https://appukili.wordpress.com/2022/04/17/take-some-rest/

    even now people working in WF etc have huge understanding problems.OT primary has professional services so there's some vested interest as well.