Discussions

Ask a Question
Back to all

404 Error while updating KPI

Hi,
I am trying to update a KPI score for a dummy_chat use case, but I am getting a 404 NotFoundError even though the KPI creation works correctly and the KPI is visible in the Pay‑I UI.

from payi import Payi
from dotenv import load_dotenv
load_dotenv()

client = Payi()

# Define a KPI for a use case type
client.use_cases.definitions.kpis.create(
    use_case_name="dummy_chat",
    name="Customer Satisfaction",
    description="Track customer satisfaction for dummy chat use case",
    kpi_type="likert5",
    goal=3
)

This above KPI creation code works well and it created a new KPI on the Pay-I UI. But when I am trying to update the KPI via the following code

from dotenv import load_dotenv
from payi import Payi
load_dotenv()

# Initialize Payi client
client = Payi()

client.use_cases.kpis.update(
    use_case_name = "dummy_chat",
    kpi_name="Customer Satisfaction",
    use_case_id = "e203fd0e-b240-481d-8394-4efd7cc8e5e0",  # obtained from get_context()
    score = 1
)
print("KPI updated successfully.")

It's throwing the following error.

Traceback (most recent call last):
  File "/home/devuser/ashirvad_workspace/Wega_Pay-i/kpi_update.py", line 8, in <module>
    client.use_cases.kpis.update(
  File "/home/devuser/ashirvad_workspace/venv/lib/python3.12/site-packages/payi/resources/use_cases/kpis.py", line 80, in update
    return self._put(
           ^^^^^^^^^^
  File "/home/devuser/ashirvad_workspace/venv/lib/python3.12/site-packages/payi/_base_client.py", line 1270, in put
    return self.request(cast_to, opts)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/devuser/ashirvad_workspace/venv/lib/python3.12/site-packages/payi/_base_client.py", line 1044, in request
    raise self._make_status_error_from_response(err.response) from None
payi.NotFoundError: Error code: 404