cubewise-code / tm1py

TM1py is a Python package that wraps the TM1 REST API in a simple to use library.
http://tm1py.readthedocs.io/en/latest/
MIT License
190 stars 109 forks source link

Syntax error with transaction log query while using USER argument #202

Closed user1493 closed 4 years ago

user1493 commented 4 years ago

I tried to perform a transaction log query using tm1.server.get_transaction_log_entries

Passed sinceargument alone and it worked: /api/v1/TransactionLogEntries?$orderby=TimeStamp desc &$filter=TimeStamp ge 2019-12-30T20:45:05Z

Passed since with user, but failed: /api/v1/TransactionLogEntries?$orderby=TimeStamp desc &$filter=User eq 'TEST/user' and TimeStamp ge 2019-12-30T20:14:57Z

Received the below error:

TM1py.Exceptions.Exceptions.TM1pyException: Text: {"error":{"code":"278","message":"Syntax error at position 10, near \"TEST\" in $filter: Expecting end of input."}} Status Code: 400 Reason: Bad Request Headers: {'Content-Length': '123', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json; charset=utf-8', 'OData-Version': '4.0'}

user1493 commented 4 years ago

Tried with cube and same result: /api/v1/TransactionLogEntries?$orderby=TimeStamp desc &$filter=Cube eq 'Sales Forecast' and TimeStamp ge 2019-12-30T21:02:03Z

TM1py.Exceptions.Exceptions.TM1pyException: Text: {"error":{"code":"278","message":"Syntax error at position 10, near \"Sales\" in $filter: Expecting end of input."}} Status Code: 400 Reason: Bad Request Headers: {'Content-Length': '124', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json; charset=utf-8', 'OData-Version': '4.0'}

MariusWirtz commented 4 years ago

Hi @user1493,

thanks for the catch!

I just looked up the latest documentation of the API. It says there that the TransactionLogEntries are not filterable by User. I think in the TM1 API they made some changes to this functionality. I'm confident that it used to work when I wrote it initially in 2018 (still on 10.2.2). I suppose if you need to filter by user, you have to do that on the client side.

For me (TM1 version 11.5.00000.23) filtering by cube + since still works though. Can you check if this works for you:

with TM1Service(address=ADDRESS, port=PORT, user=USER, password=PASSWORD, ssl=SSL) as tm1:
    entries = tm1.server.get_transaction_log_entries(cube="Sales Forecast", since=datetime.fromisoformat("2019-12-30"))
    for entry in entries:
        print(entry)
user1493 commented 4 years ago

Hi Marius,

Yes, I tried with cube and since parameters. I received the same error this time. I posted the same in my earlier comment.

I do see User and Cube as entities, but not sure why they would remove them.

Also would you be able to point me the link for the API documentation?

user1493 commented 4 years ago

Tested again: Both Cube and User are not queryable.

log = tm1.server.get_transaction_log_entries(since=timestamp, cube='Sales Forecast')

TM1py.Exceptions.Exceptions.TM1pyException: Text: {"error":{"code":"278","message":"Syntax error at position 48, near \"Sales\" in $filter: Expecting end of input."}} Status Code: 400 Reason: Bad Request Headers: {'Content-Length': '124', 'Connection': 'keep-alive', 'Content-Encoding': 'gzip', 'Cache-Control': 'no-cache', 'Content-Type': 'application/json; charset=utf-8', 'OData-Version': '4.0'}

MariusWirtz commented 4 years ago

Hi @user1493 ,

thanks for double checking. It seems IBM did some changes to the API.

The part in the documentation (metadata xml) that I meant is this.

<EntitySet Name="TransactionLogEntries" EntityType="tm1.TransactionLogEntry">
<Annotation Term="Capabilities.ChangeTracking">
<Record>
<PropertyValue Property="FilterableProperties">
<Collection>
<PropertyPath>ChangeSetID</PropertyPath>
<PropertyPath>TimeStamp</PropertyPath>
<PropertyPath>ReplicationTime</PropertyPath>
<PropertyPath>Cube</PropertyPath>
<PropertyPath>Tuple</PropertyPath>
<PropertyPath>OldValue</PropertyPath>
<PropertyPath>NewValue</PropertyPath>
<PropertyPath>StatusMessage</PropertyPath>

You can open it in the browser through this url: https://localhost:<<RESTPORT>>/api/v1/$metadata

Please check which fitlerable properties it lists there for you.

user1493 commented 4 years ago

I see the same collections you posted in TM1 servers $metadata. I tried to work around the GET requests.

To my surprise the below request works:

/api/v1/TransactionLogEntries?$filter=Cube ne ''

But below does not:

/api/v1/TransactionLogEntries?$filter=Cube eq 'Sales Forecast'

The first request proves that Cube is queryable. Also the first request returned logs for 'Sales Forecast' cube.

MariusWirtz commented 4 years ago

It seems like a bug in your version of TM1. Which version are you on?

with TM1Service(address=ADDRESS, port=PORT, user=USER, password=PASSWORD, ssl=SSL) as tm1:
    print(tm1.version)
user1493 commented 4 years ago

The TM1 application's version I'm working on is 11.4.00009.4

I will upgrade TM1 soon and test the same. For now I'm handling things client side, so I'm closing this thread.

Thank you very much for your support!