Page 1 of 1

TM1py SaaS

Posted: Wed Jul 16, 2025 1:04 pm
by rachanaharia
Hi, we have created an API gateway to connect to a third party API, we are able to make connections to TM1 REST API via the postman, We are looking to make the connection using these credentials for using TM1py.
The normal connection string (w/o API gateway) for connecting to TM1py looks something like this and is working fine.
--------------------------------------
params = {
"base_url": url,
"user": "apikey",
"password": '',
"async_requests_mode": True,
"ssl": True,
"verify": True,

}
return TM1Service(**params)
-----------------------------------------

In order to use the API gateway we need to pass 2 tokens:
1) "Authorization": f"Bearer {dx_requestor}", (coming from requestor). used to validate on client side
2) "X-Authorization": "Basic XYZ" (using the basic encode) used to validate the IBM side.
Both these tokens need to be passed as headers for TM1py connection.

This is what I am looking to pass
------------------------------------------------------
url = f"{DX_GATEWAY}{endpoint}"
headers = {
"Accept": "application/json;v=1",

"Content-Type": "application/json",
"Authorization": f"Bearer {dx_requestor}",
"X-Authorization": "Basic XYZ",

}
-------------------------------------------------------
My question here is how to pass these tokens as header in TM1py connection string.
Thanks!

Re: TM1py SaaS

Posted: Thu Jul 17, 2025 9:30 pm
by MariusWirtz
Currently there is no very elegant way to specify additional custom HTTP headers that TM1py should send with each request to TM1.

However, you can manipulate the HEADERS dictionary in the RestService class that maintains the default set of headers that TM1py uses.
If you do this before you initiate the TM1Service this will work. Below is an example that specifies an additional HTTP Header ("TM1-SessionContext") to overrule what gets displayed in the session context in tools like PAW and Arc.

Code: Select all

from TM1py import TM1Service, RestService

tm1_params = {
    "base_url": "https://company.planning-analytics.ibmcloud.com/tm1/api/tm1",
    "user": "company01_tm1_automation",
    "namespace": "LDAP",
    "password": "...",
    "ssl": True,
    "verify": True,
    "async_requests_mode": True,
}

RestService.HEADERS["TM1-SessionContext"] = "The Best TM1 Session"

with TM1Service(**tm1_params) as tm1:
    success, status, error_log_file = tm1.processes.execute_with_return(
        process_name="}bedrock.server.wait",
        pWaitSec=60)

Image


Marius