TM1 client · Walkthrough 1 of 3
Connect and list your cubes
You connect to a TM1 server, ask for its version, and list its cubes. Each step shows its code in your language, and what it printed when we ran it against IBM's SData sample.
Before you start
- A TM1 server with IBM's SData sample. Run Planning Analytics on your own computer starts one if you ask for the sample too. It answers at
http://localhost:8011/api/v1/, and you log in asadminwith the passwordapple. You need your own licensed copy of TM1 Server.
Steps
Add the client to your project.
Needs Java 17 or later.
Gradle (Kotlin)
implementation("io.skipcheck:tm1-client:0.1.1")Maven
<dependency> <groupId>io.skipcheck</groupId> <artifactId>tm1-client</artifactId> <version>0.1.1</version> </dependency>Needs Python 3.11 or later.
Terminal
pip install skipcheck-tm1==0.1.1Needs .NET 10.
Terminal
dotnet add package Skipcheck.Tm1.Client --version 0.1.1Needs Node 22 or later.
Terminal
npm install @skipcheck/tm1-client@0.1.1Make a client. Give it the server's address and your login. Nothing is sent to the server yet.
// The SData sample's address and login Tm1Client tm1 = Tm1Client.builder() .baseUrl("http://localhost:8011/api/v1/") .basicAuth("admin", "apple") .build();# The SData sample's address and login tm1 = Tm1Client.builder().base_url("http://localhost:8011/api/v1/").basic_auth("admin", "apple").build()// The SData sample's address and login var tm1 = Tm1Client.Builder().BaseUrl("http://localhost:8011/api/v1/").BasicAuth("admin", "apple").Build();// The SData sample's address and login const tm1 = Tm1Client.builder().baseUrl("http://localhost:8011/api/v1/").basicAuth("admin", "apple").build();Check the connection. The first call logs in. Ask for the server's version:
// Each call returns a Mono or a Flux, which does nothing until asked: // block() waits for its result, which is fine in a main() Tm1Version version = tm1.session().version().block(); System.out.println("Connected to TM1 " + version);Output
Connected to TM1 11.8.03500.6# The client logs in on its first call version = tm1.session.version() print(f"Connected to TM1 {version}")Output
Connected to TM1 11.8.03500.6// Each call returns a Task, or an IAsyncEnumerable for a collection, which you await for its result var version = await tm1.Session.VersionAsync(); Console.WriteLine($"Connected to TM1 {version}");Output
Connected to TM1 11.8.03500.6// Each call returns a promise: await waits for its result const version = await tm1.session.version(); console.log(`Connected to TM1 ${version}`);Output
Connected to TM1 11.8.03500.6If it fails, check the address, the port and the login. TM1's REST API ends in
/api/v1/.List the cubes. These are the cubes someone made. TM1's control cubes, whose names start with
}, are left out:// The cubes you made, without TM1's control cubes; select asks for // their names alone for (Cube cube : tm1.cubes().modelCubes(ODataQuery.none().select(Cube.NAME)).toIterable()) { System.out.println(cube.name()); }Output
PNLCube PriceCube SalesByQuarterCube SalesByQuarterCube-TotalModel SalesCube SalesCube_metrics SalesPriorCube# The cubes you made, without TM1's control cubes; select asks for their names alone for cube in tm1.cubes.model_cubes(ODataQuery.none().select(Cube.NAME)): print(cube.name)Output
PNLCube PriceCube SalesByQuarterCube SalesByQuarterCube-TotalModel SalesCube SalesCube_metrics SalesPriorCube// The cubes you made, without TM1's control cubes; Select asks for their names alone await foreach (var cube in tm1.Cubes.ModelCubesAsync(ODataQuery.None().Select(Cube.Fields.Name))) { Console.WriteLine(cube.Name); }Output
PNLCube PriceCube SalesByQuarterCube SalesByQuarterCube-TotalModel SalesCube SalesCube_metrics SalesPriorCube// The cubes you made, without TM1's control cubes; select asks for their names alone for await (const cube of tm1.cubes.modelCubes(ODataQuery.none().select(Cube.Fields.Name))) { console.log(cube.Name); }Output
PNLCube PriceCube SalesByQuarterCube SalesByQuarterCube-TotalModel SalesCube SalesCube_metrics SalesPriorCubeClose the client. This logs out and ends your session on the server.
// Ends the session on the server tm1.close().block();# Ends the session on the server; a with block around the client does it for you tm1.close()// Ends the session on the server await tm1.CloseAsync();// Ends the session on the server await tm1.close();
Next
Read and write cells in SalesCube, one of these cubes. Or look through the client, which has a service for each area of TM1, such as cubes.
More walkthroughs
- Read and write cells: Read values from a cube with MDX, write a value, and read it back.
- Run a process and read its result: Create a TurboIntegrator process, run it with a parameter, check what it did, and read why a run failed.