Pyton Celonis API : Creating a new datamodel in 4.5 not connecting

#1

Hello Everyone,

I am trying to connect data model in Celonis 4.5 from Python and trying to import tables.
Execution is failing while creating data model.

Error From Python-
Traceback (most recent call last):

File “C:\Users<User_Name>\AppData\Local\Continuum\anaconda3\lib\site-packages\celonis_tools\model\folder.py”, line 2191, in create_new
return super(DBConnection, cls).create_new(parent, **data)

File “C:\Users<User_Name>\AppData\Local\Continuum\anaconda3\lib\site-packages\celonis_tools\model\resource.py”, line 360, in create_new
return obj.create()

File “C:\Users<User_Name>\AppData\Local\Continuum\anaconda3\lib\site-packages\celonis_tools\model\resource.py”, line 230, in create
ret = self.api.post(*args, params=kw, **self.data)

File “C:\Users<User_Name>\AppData\Local\Continuum\anaconda3\lib\site-packages\celonis_tools\api.py”, line 108, in post
ret = self.session.post(url, params=params, json=kw or None)

File “C:\Users<User_Name>\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\sessions.py”, line 555, in post
return self.request(‘POST’, url, data=data, json=json, **kwargs)

File “C:\Users<User_Name>\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\sessions.py”, line 508, in request
resp = self.send(prep, **send_kwargs)

File “C:\Users<User_Name>\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\sessions.py”, line 625, in send
r = dispatch_hook(‘response’, hooks, r, **kwargs)

File “C:\Users<User_Name>\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\hooks.py”, line 31, in dispatch_hook
_hook_data = hook(hook_data, **kwargs)

File “C:\Users<User_Name>\AppData\Local\Continuum\anaconda3\lib\site-packages\celonis_tools\api.py”, line 232, in parse_result
raise CelonisRequestError®

CelonisRequestError: 400 Client Error: Bad Request for url
http:///api/datamodel/161/connections/

Code I implemented in Python:
Establishing connection with Celonis with API token:
conn = DBConnection.create_new(dm,"<Database_name>","",
“”,
“”,", “”,, “jdbc:sap”)
t = dm.import_table(conn, “<table_name>”)
dm.reload()

From Document:
conn = DBConnection.create_new(dm, “My Connection”, “mssql”, “localhost”, “user”,
˓→"password", “test_db”, 1433, “dbo”)
t = dm.import_table(conn, “table_name”)
dm.reload()

  1. Is there any parameter i am missing?
  2. Can we load multiple tables at a time?

Please assist on this.

Thanks,
Parimala

#2

Hello Parimala,

can you please describe how you setup your connection to Celonis in Python? You need to create a CelonisSession in python, according to https://help.celonis.de/pages/viewpage.action?pageId=18743853#id-1.0.0/Quickstart-Authentication

It seems like the CelonisSession is not created correctly.

Best
David

#3

Hello David,

I have set the connection as below:

with CelonisSession(“https://localhost:9000”, “your_username”, api_token=“your_token”, api_secret=“your_secret”) as session:
–write your code here –
conn = DBConnection.create_new(dm, “<Connection_Name>”, “HANA”, “<host_name>”, “<User_Name>”,"<_password>", “<Schema_Name>”, <-port>, “<driver_name> Ex: jdbc:sap”)
t = dm.import_table(conn, “table_name”)
dm.reload()

#4

Hello Parimala,

I just tried it, and for me, it works.
Does getting the datamodel work?:
dm = DataModel(42)
where 42 is your datamodel ID.

Did you enter the correct connection details in the CelonisSession (Host, Port, Username, API-Key, API-Token) and of your database you want to connect to? For HANA, you need to use “hana” (all lowercase) as the template specifier (third argument of DBConnection.create_new().

Best,
David

#5

Hello David,

Yes Celonis session is working.

with CelonisSession(“https://localhost:9000”, “your_username”, api_token=“your_token”, api_secret=“your_secret”) as session:
dm = DataModel(161) # My data model number.

But I would like to know :
DBConnection.create_new () generic parameter list like
DBConnection.create_new (host_name,port_num,schema_name,…etc)
I couldn’t find in document in generic way.

#6

Hello,

the DBConnection.create_new takes the following parameters:

conn = DBConnection.create_new(DataModel, Name, Template, host, Username, Password, Database, Port, Schema)

  • DataModel: Your datamodel
  • Name: The name your DB connection should have
  • Template: The template identifier. Can be "hana", "hana ssl" or "hana ssl no validation" if you’d like to connect to a HANA
  • Host: the host name of the database
  • Username: The database user to use
  • Password: The password of the Database user
  • Database: The name of the Database to connect to
  • Port: The port to use (as an integer). For HANA, it should be 30015
  • Schema: The database schema name

You can then use t = dm.import_table(conn, “table_name”) to add the table with table_name to the datamodel.

#7

Hello David,

Thanks for providing detailed generic information.
Following steps are performed so far:

  1. Created session with Celonis using API key.
  2. Connected to Data model from data model ID
  3. Established the connection to data model.
  4. Loaded a table using t = dm.import_table(conn, “<Test_Table>”) (Test Table is existed in Database).

I couldn’t see the tables in list of tables under DataSources>Import Data.
Screenshot :

I would like to understand what exactly this statement do ? dm.reload() as i understood after running this statement table data has to load. Could you please brief on this.

Thanks,
Parimala N

#8

Hello Parimala,

this looks like either you specified the wrong schema name (check again if you spelled the schema name correctly), or the schema does not include any tables, or the Database user you are using doesn’t have the rights to access the schema or the tables.

Best regards
David

#9

Hello David,

When i try to create manually with same details I am able to see connections and relevant tables.
Same when using Python facing issue :
Connection Status from Celonis ( via Python). Data source is getting connected below is screenshot reference.


Table List Error: (Empty List)

My Code:

Code_datasource_connection.txt (464 Bytes)

#10

Hello,

can you please check if all the credentials are correct in Celonis? So click on the “edit” button of the connection you created in python and check if everything is correct, especially the connection string. Also compare all credentials to the working connection you created in Celonis.

I currently have no idea why it is not working.

Best
David

#11

Hello David,

I have checked the credentials too , all are correct. Connection strings are below like this:

#12

Hello,

thanks for checking! Unfortunately, I cannot tell what the problem is just based on the given information.
Could you please write a ticket to our servicedesk ( https://servicedesk.celonis.com/ )? Then we have the possibility to investigate your problem further.

Thanks for your patience!
David

#13

something that I learned the hard way is that schema names are case sensitive. Is this something you checked @parimala?

2 Likes
#14

Yes i checked too everything is as it is. But now its showing list of tables under Tables in Database nothing has changed in my code much regarding DB parameters. ( Initially i tested 4.5 beta version may be now our server upgraded to official version of 4.5, that might be the only change i can see :wink:

My next task is to import the all listed tables through python.

1 Like
#15

Hi,

after creating the connection, you can get the table names using
table_names = conn.get_table_names()

You can then loop through the list of table names and add them to your data model:
for table_name in table_names:
dm.import_table(conn, table_name)

In order to get the data in your datamodel, you need to reload it:
dm.reload()

Best,
David

#16

Yeah David it worked. Thanks for support.
But initially when data source is loading I could see all list of tables from my schema and there are almost 10-15 tables.

When it comes to status is see only one table loads.

#17

You only need to reload the datamodel once, so execute dm.reload() only once after the loop in which you add the tables to the datamodel.
Then it should load all the tables at once.

#18

Yes i am doing once.
conn = <_Data source connection>
table_names = conn.get_table_names()
for table_name in table_names:
dm.import_table(conn, table_name)
dm.reload()