Planning Analytics

Planning Analytics

Get AI-infused integrated business planning

 View Only
Expand all | Collapse all

Modify / Create Application entries through REST API

  • 1.  Modify / Create Application entries through REST API

    Posted Fri October 25, 2019 08:56 AM
    @here I have got the following question in one of my support tickets
    *We would like to maintain application entries in PA through the REST API*

    Using the REST API we tested and are able to achieve the following:
    - Delete certain application entries
    - Create new Folders
    - Create and Update Workbooks
    - Create Links (URLs/ref. to external files)

    Additionally, we would like to create/update the following objects as application entries:
    - ProcessReference
    - ChoreReference
    - DimensionReference
    - SubsetReference
    - CubeReference
    - ViewReference

    As I wasn't able to find any documentation on this, could someone please provide us with example REST calls for this second block? Or let me know if that is documented somewhere?

    We are not asking how to create/update these PA objects. This is documented.
    We are asking how to create references to these objects in the application tree folders through the REST API.
    Using the client tools, you can publish views, processes, subsets, and other objects in the application tree.
    We want to maintain them using the REST API. -> Workbooks and external links are working, and we are looking for the rest :)

    Can someone help me out?

    ------------------------------
    Michael Ehrenberger
    ------------------------------

    #PlanningAnalyticswithWatson


  • 2.  RE: Modify / Create Application entries through REST API
    Best Answer

    Posted Tue October 29, 2019 02:53 AM
    All those xxxReference types inherit from the Entry base type. You should be able to use any of the reference types in all the same places as an Entry. Commonly, a Folder.Contents would be the container collection you could POSTPATCHDELETE to

    ------------------------------
    Michael Ehrenberger
    Technical Analyst
    IBM
    Vienna
    ------------------------------



  • 3.  RE: Modify / Create Application entries through REST API

    Posted Mon November 04, 2019 12:39 PM
    Hi Michael,

    Creating those reference entities is just the same as any other type of entity, with the exception perhaps, if you haven't created views for example, that you have to specify the type as well.

    So, using Planning Sample, if you wanted to add a reference to the "Budget Total Input" view from the plan_BudgetPlan cube into the "Planning Sample" folder under application you would POST using a URL similar to:

    http://tm1server:12555/api/v1/Contents('Applications')/Contents('Planning Sample')/Contents

    where the body would describe the 'Entry' you are trying to post to the contents of that folder, in this case, a 'ViewReference' as in:

    {
        "@odata.type":"tm1.ViewReference",
        "Name":"Reference to plan_BudgetPlan's Budget Input Total View",
        "View@odata.bind":"Cubes('plan_BudgetPlan')/Views('Budget Input Total')"
    }

    ------------------------------
    Hubert Heijkers
    ------------------------------



  • 4.  RE: Modify / Create Application entries through REST API

    Posted Mon November 11, 2019 09:45 AM
    Hi Tomasz,

    Please allow me to inject your follow up question here (no worries, I've had my fair share of struggles with this forum myself;-):

    ------------------------------
    ------------------------------

    First off all thank you for sharing reference creation example. This helped me to solve all object reference creation problems.
    The only outstanding issue is the modification/patching of the references.
    Is the renaming of references supported?

    The below PATCH request is not working for me. 
    https://tm1server:8030/api/v1/Contents('Applications')/Contents('Test')/Contents('somedim.dimension')


    Body:
    {
       "Name": "Test"
    }


    Response:


    {
       "error": {
          "code": "278",
          "message": "PATCH not supported on this resource!"
       }
    }
    ------------------------------------------------------------

    Had to quickly look it up but it indeed appears that we haven't implemented support for PATCH on these references just yet. Now keep in mind you'd never be able to change the Name property anyway as the Name property is the Key and key property, following the OData standard, are immutable. 
    As such only the referenced view (read: the View property), in case of a view reference, would have been the only editable property. I'm guessing you are the first to ask and that it was kind of assumed that in these cases references would be deleted and re-added to the containing folder again. I'm sure we'll add support for PATCH at some point in the future, allowing you just to edit the referenced entry, but for now deleting and re-adding would be the way the only way to accomplish changing the referenced entry I'm afraid.



    ------------------------------
    Hubert Heijkers
    ------------------------------



  • 5.  RE: Modify / Create Application entries through REST API

    Posted Mon November 11, 2019 09:54 AM
    Edited by System Admin Fri January 20, 2023 04:38 PM


  • 6.  RE: Modify / Create Application entries through REST API

    Posted Mon November 11, 2019 09:57 AM
    Hi Hubert,

    thank you for sharing this example. This helped me to solve all object reference creation problems.
    The only outstanding issue is the modification/patching of the references.

    Is the renaming of references supported?

    DELETE works as expected, but the below PATCH request isn't working for me. 

    https://tm1server:8030/api/v1/Contents('Applications')/Contents('Planning Sample')/Contents('myDimension.dimension')
    
    Body:
    {
       "Name": "new name"
    }


    Response:
    {
        "error": {
            "code": "278",
            "message": "PATCH not supported on this resource!"
        }
    }


    ------------------------------
    Tomasz Brzoza
    ------------------------------



  • 7.  RE: Modify / Create Application entries through REST API

    Posted Mon November 11, 2019 05:01 PM
    Hi Tomasz,

    Seems your message showed up after all (This community software is even more of an enigma than anything I've ever used before;-), trust you've seen my response to your message above already;-!

    Cheers, -H

    ------------------------------
    Hubert Heijkers
    ------------------------------



  • 8.  RE: Modify / Create Application entries through REST API

    Posted Mon November 11, 2019 06:35 PM
    Hi Hubert,

    Yes, very strange behavior. Let's hope it happened because it was my very first post.

    Thank you once again for checking and explanations.
    It would be great if a limited PATCH could be implemented in the future.
    I can live with it, that the name cannot be changed as it is the key property, but the change of odata.bind for the below objects would be appreciated.

    • Process reference
    • View reference
    • Subset reference
    • Chore reference
    • External Link Reference

    In the actual implementation we will use the delete and recreate approach but the PATCH would look more "elegant" in the coding 😊.

    Cheers,
    Tomasz

    ------------------------------
    Tomasz Brzoza
    München
    +4915110934194
    ------------------------------



  • 9.  RE: Modify / Create Application entries through REST API

    Posted Mon November 11, 2019 09:57 AM
    Edited by System Admin Fri January 20, 2023 04:12 PM


  • 10.  RE: Modify / Create Application entries through REST API

    Posted Mon March 17, 2025 09:58 AM

    Hi @Hubert Heijkers,

    I try to create/publish an xlsx file(websheet) to a folder application (e.g. Applications/PlanningSample).

    I know the rest api call, but what should be the body when creating a xlsx/xlsm document?



    ------------------------------
    Mahmut Yuksel
    ------------------------------



  • 11.  RE: Modify / Create Application entries through REST API

    Posted Tue March 18, 2025 01:22 AM
    Edited by Hubert Heijkers Tue March 18, 2025 01:25 AM

    Hi @Mahmut Yuksel,

    Creating a document is a two step process. First you create (POST) the entity that represents the document and then you update (PUT) the contents to the Content property of the Document entry you created in the previous step.

    So in your case you want to create a document by sending a:

    ```

    POST http://{{host}}:{{port}}/api/v1/Contents('Applications')/Contents('PlanningSample')
    Content-Type: application/json

    {
       
    "@odata.type\" : \"ibm.tm1.api.v1.Document",
        "Name": "Name-of-document"
    }

    ```

    After the document is created you issue the second request which is a regular PUT request of writing the document's (read: file's) contents:

    ```

    PUT http://{{host}}:{{port}}/api/v1/Contents('Applications')/Contents('PlanningSample')/Contents('Name-of-document')/Content
    Content-Type:
    application/octet-stream

    <<the-raw-binary-content-of-the-file>>

    ```

    Again, this second request is a generic HTTP PUT request to a file resource endpoint where the stream property of the target entity, the Content property in this case, is the target resource.

    Hope this helps,



    ------------------------------
    Hubert Heijkers
    STSM, Program Director TM1 Functional Database Technology and OData Evangelist
    ------------------------------



  • 12.  RE: Modify / Create Application entries through REST API

    Posted Tue March 18, 2025 01:39 PM

    Hi @Hubert Heijkers,

    Many thanks for your explanation, finally it worked. I just want to correct the little detail in the PUT call as without it, it doesn't work for me.

    PUT http://{{host}}:{{port}}/api/v1/Contents('Applications')/Contents('PlanningSample')/Contents('Name-of-document')/Document/Content
    Content-Type:
    application/octet-stream

    And I want to share a powershell script that I used:

    $applicationPath = "Analysis/Test"
    $file = "ET2019 Personnel.xlsx"
    $import_path = "E:\IBM Demos\24Retail"
    
    $splitAppPath = $applicationPath -split "/"
    if ($splitAppPath.Length -eq 1) {
        $formattedAppPath = "Contents('$($splitAppPath[0])')"
    } else {
        $formattedAppPath = ($splitAppPath  | ForEach-Object { "Contents('$_')" }) -join "/"
    }
    
    $formattedFile = "Contents('"+ $file + ".blob')"
    
    $import_file_path = $import_path + '\' + $file
    [byte[]]$binaryContent = [System.IO.File]::ReadAllBytes("$import_file_path")
    
    $params_PUT = @{
        Uri = "http://localhost:55130/api/v1/Contents('Applications')/" + $formattedAppPath + "/" + $formattedFile + "/Document/Content"
        Headers = @{ 'Authorization' =  $psw}
        Method = 'PUT'
        ContentType = 'application/octet-stream'
    	Body = $binaryContent
    }
     
    Invoke-RestMethod @params_PUT

     



    ------------------------------
    Mahmut Yuksel
    ------------------------------



  • 13.  RE: Modify / Create Application entries through REST API

    Posted Tue March 18, 2025 07:30 PM

    Hi@Mahmut Yuksel,

    My bad, you are right, the Content property is of the Document sub type and therefore you need the type segment. I'm surprised however that seems to work though without the namespace or namespace alias, it  should read 'ibm.tm1.api.v1.Document' or, using the namespace alias, 'tm1.Document'. I'll make a note of this 'bug'!

    Cheers,



    ------------------------------
    Hubert Heijkers
    STSM, Program Director TM1 Functional Database Technology and OData Evangelist
    ------------------------------