Update a process with the TM1 REST API

Post Reply
Wim Gielis
MVP
Posts: 3105
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Update a process with the TM1 REST API

Post by Wim Gielis »

Hi all,

I am trying to use Postman to update an existing, very simple, TI process.

The only line of code is: v = 1; in the Prolog tab. No data source, no variables, etc.
I want to update the process to read: v = 2; Can it be even more simple ? :-) The process is called 'test'. TM1 basic security, I am admin for the test.
PAL 2.0.9.10.

So I have this:

Code: Select all

GET: http://AEX220:8001/api/v1/Processes('test')
Result:

Code: Select all

{
    "@odata.context": "$metadata#Processes/$entity",
    "@odata.etag": "W/\"322acd39b78e9283c769d29d901f4c3e04792b58\"",
    "Name": "test",
    "HasSecurityAccess": false,
    "PrologProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****\r\n\r\n\r\nv = 1;",
    "MetadataProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****",
    "DataProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****",
    "EpilogProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****",
    "DataSource": {
        "Type": "None"
    },
    "Parameters": [],
    "Variables": [],
    "Attributes": {
        "Caption": "test"
    }
}
I change the v = 1 into v = 2 and I copy the whole lot into the JSON body for a PATCH statement, I get an error for "Bad request":

Code: Select all

{
    "error": {
        "code": "278",
        "message": "Cannot modify Attributes property during Process PATCH."
    }
}
(see below for a picture)

When I then manually delete the Attributes part in the JSON body and send the PATCH request again, it works:

Code: Select all

{
    "@odata.context": "$metadata#Processes/$entity",
    "@odata.etag": "W/\"322acd39b78e9283c769d29d901f4c3e04792b58\"",
    "Name": "test",
    "HasSecurityAccess": false,
    "PrologProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****\r\n\r\n\r\nv = 2;",
    "MetadataProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****",
    "DataProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****",
    "EpilogProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****",
    "DataSource": {
        "Type": "None"
    },
    "Parameters": [],
    "Variables": []
}
(see below for a picture)

The process is not part of any chore.

Did any of you encounter it before ? When I reverse engineer in tm1py, it does not seem to me that tm1py is doing anything with the body of the request. Certainly nothing with Attributes. Any help is greatly appreciated !

Thanks.
Attachments
bad request.PNG
bad request.PNG (69.55 KiB) Viewed 1665 times
01.PNG
01.PNG (88.21 KiB) Viewed 1665 times
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Wim Gielis
MVP
Posts: 3105
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Update a process with the TM1 REST API

Post by Wim Gielis »

Marius Wirtz confirms that we should not do anything with the Attributes property when updating a process.
Either we strip it from the JSON body (result of a GET call), either we select the process properties we need (and exclude the Attributes property from that list).
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
dan.kelleher
Community Contributor
Posts: 127
Joined: Wed Oct 14, 2009 7:46 am
OLAP Product: TM1
Version: 9.4
Excel Version: 11
Location: London

Re: Update a process with the TM1 REST API

Post by dan.kelleher »

Another solution I have found is to simply delete the existing process from the target server and then re-add:

Code: Select all

$url = $url = "http://${targetServer}:${TargetPort}/api/v1/Processes('$processName')"
$header = Set-Header $targetUser $targetPass

$response = Invoke-WebRequest -Uri $url -Method Delete -Headers $header
$response = Invoke-WebRequest -Uri $url -Method Put -Headers $header -Body $body
Does anyone know if there's a way to remove the Attributes property from the initial GET?
Wim Gielis
MVP
Posts: 3105
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Update a process with the TM1 REST API

Post by Wim Gielis »

What happens to the security assignments for the process, when you delete and recreate ?
In general, I try to update rather than recreate, to not lose other settings.
Another example, data against the process in the }Processes dimension in a cube: is it lost or not, when deleting and recreating ?
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
dan.kelleher
Community Contributor
Posts: 127
Joined: Wed Oct 14, 2009 7:46 am
OLAP Product: TM1
Version: 9.4
Excel Version: 11
Location: London

Re: Update a process with the TM1 REST API

Post by dan.kelleher »

Yes, these are lost so need to be re-added, which is probably more work than removing the attributes property from the body.
dan.kelleher
Community Contributor
Posts: 127
Joined: Wed Oct 14, 2009 7:46 am
OLAP Product: TM1
Version: 9.4
Excel Version: 11
Location: London

Re: Update a process with the TM1 REST API

Post by dan.kelleher »

Just in case anyone's interested, I worked out how to remove the attributes property via Powershell:

Code: Select all

...
$response = Invoke-WebRequest -Uri $url -Method Get -Headers $header

$x = $response.content | ConvertFrom-Json
$x = $x | Select-Object * -ExcludeProperty Attributes
$body = $x | ConvertTo-Json

$url = $url = "http://${targetServer}:${TargetPort}/api/v1/Processes('$processName')"
$header = Set-Header $targetEncodedText
$response = Invoke-WebRequest -Uri $url -Method Patch -Headers $header -Body $body
Wim Gielis
MVP
Posts: 3105
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Update a process with the TM1 REST API

Post by Wim Gielis »

Good, elegant, solution.

Minor remark, you have the $url = part twice.
Best regards,

Wim Gielis

IBM Champion 2024
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Post Reply