Error on delete positions API

axelT 3 years ago

First of all, allow me to thank you for your wonderful work on Traccar!

I am trying to use the delete API (Traccar 5.7) on the /api/positions end point, I get this error:

Parameter "#2" is not set; SQL statement:
DELETE FROM tc_positions WHERE deviceId = ? AND fixTime BETWEEN ? AND ? [
    90012-214
] - JdbcSQLDataException (... < QueryBuilder: 469 < DatabaseStorage: 131 < PositionResource: 101 < ...)

The body of my DELETE request is

{
    "deviceId": "12345",
    "from": "2023-04-19T22:00:00Z",
    "to": "2023-04-20T22:00:00Z"
}

I tried this request from Node Red and Postman, same error.

Any ideas what I could be doing wrong?

Thanks for your help!

Alex

Anton Tananaev 3 years ago

Please make sure you carefully read our API documentation. There's no JSON body. You have to send query parameters.

axelT 3 years ago

I am an idiot, thanks!!

I no longer get the error ( get a 204 in return), the ULR seems correctly built:

http://x.x.x.x:8082/api/positions?deviceId=1111&from=2023-04-19T22:00:00Z&to=2023-04-20T22:00:00Z

This should delete all points of device 1111 for today, but they are not deleted. Am I doing something wrong?

Anton Tananaev 3 years ago

Maybe some timezone issue. Have you tried removing longer period?

axelT 3 years ago

Yes, same issue, I tried with a full week. I will test further and let you know if I am able to find what the issue could be. Thanks!

Anton Tananaev 3 years ago

You can enable SQL query logging and see what is actually executed.

axelT 3 years ago

Hi,
This is what I see in the logs:

2023-04-20 22:47:39  INFO: SELECT * FROM tc_users WHERE email = :email OR login = :login
2023-04-20 22:47:39  INFO: SELECT * FROM tc_users WHERE id = :id
2023-04-20 22:47:39  INFO: DELETE FROM tc_positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to

Is there a way to see the actual values? Thanks!

Anton Tananaev 3 years ago

I don't think so. Are you sure the device id you're using is correct?

axelT 3 years ago

OK I see now my mistake. I wasn't using the device Id but the identifier.

What is the difference between the "identifier", "id" and "device id"?

Thanks for your support!!

Anton Tananaev 3 years ago

External id is called "uniqueId". Everything else is referring in the internal id, which is the index in the table.

axelT 3 years ago

OK, it's clear now. Thanks again!