Skip to main content
Solved

Can't update changes using pyCelonis to Knowledge Model


Floboyo
Level 3
Forum|alt.badge.img+5

I've written a basic script to access a knowledge model and want to edit its PQL and update it to the cloud.

 

space = celonis.studio.get_spaces().find('Value Monitoring')

package = space.get_packages().find('Value Monitoring')

knowledge_model = package.get_knowledge_models().find('Value Monitor-devFlo2')

content = knowledge_model.get_content()

kpis = knowledge_model.get_kpis()

kpis[0].pql

kpi = kpis[0]

kpi.pql = "Test"



knowledge_model.update()  # local to EMS

 

The ML Workbench has "USE" rights on the knowledge model (no other options available) and "USE and EDIT" rights in the package.

 

These are the logs:

[2025-01-09 18:38:30,804] INFO: No `base_url` given. Using environment variable 'CELONIS_URL'
[2025-01-09 18:38:30,805] INFO: No `api_token` given. Using environment variable 'CELONIS_API_TOKEN'
[2025-01-09 18:38:30,853] WARNING: Your PyCelonis Version 2.11.1 is outdated (Newest Version: 2.12.0). Please upgrade the package via: pip install --extra-index-url=https://pypi.celonis.cloud/ pycelonis pycelonis_core --upgrade
[2025-01-09 18:38:30,884] WARNING: KeyType is not set. Defaulted to 'APP_KEY'.
[2025-01-09 18:38:30,904] INFO: Initial connect successful! PyCelonis Version: 2.11.1
[2025-01-09 18:38:31,123] INFO: `package-manager` permissions: ['$ACCESS_CHILD', 'EDIT_ALL_SPACES', 'MANAGE_PERMISSIONS', 'CREATE_SPACE', 'DELETE_ALL_SPACES']
[2025-01-09 18:38:31,124] INFO: `task-mining` permissions: []
[2025-01-09 18:38:31,125] INFO: `compute-live` permissions: []
[2025-01-09 18:38:31,125] INFO: `action-engine` permissions: []
[2025-01-09 18:38:31,126] INFO: `workflows` permissions: []
[2025-01-09 18:38:31,126] INFO: `team` permissions: []
[2025-01-09 18:38:31,127] INFO: `process-repository` permissions: []
[2025-01-09 18:38:31,127] INFO: `transformation-center` permissions: []
[2025-01-09 18:38:31,129] INFO: `storage-manager` permissions: []
[2025-01-09 18:38:31,129] INFO: `event-collection` permissions: ['$ACCESS_CHILD']
[2025-01-09 18:38:31,130] INFO: `user-provisioning` permissions: []
[2025-01-09 18:38:31,131] INFO: `ml-workbench` permissions: ['USE_ALL_APPS', 'VIEW_CONFIGURATION']



Why can't I update my changes from the python notebook into the EMS?

Best answer by Floboyo

ok I found my mistake. Instead of the knowledge model object one should apply the update function on the KPI object.

Not: knowledge_model.update()

Do: kpi.update()

View original

matt.witty13
Level 5

Depending on your version of PyCelonis, there are a couple of ways to do it. If you’re using the most recent version, here is the code chunk you’re looking for.

kpi = knowledge_model.create_kpi(
    id_="TEST_KPI",
    display_name="Test KPI",
    pql='COUNT("BSEG"."BELNR")',
)

This is where I got it from - link


Floboyo
Level 3
Forum|alt.badge.img+5
  • Level 3
  • January 10, 2025

@matt.witty13 I can create new KPIs using the provided snippet, however I can’t edit old already existing ones, that is what I am having problems with.


Floboyo
Level 3
Forum|alt.badge.img+5
  • Level 3
  • January 10, 2025

ok I found my mistake. Instead of the knowledge model object one should apply the update function on the KPI object.

Not: knowledge_model.update()

Do: kpi.update()


matt.witty13
Level 5

Ah misunderstood your question! Yes fantastic. The PyCelonis page is very informative.


Reply