Filter events by time it created

Hi there,

Is there any way to filter by api point /api/analytics/events/query/ an events by their date of creation? for example by assigning timeField=created? I know it is possible filter event by EVENT_DATE | SCHEDULED_DATE | | . But I need to filter them by the date of creation.

Another question is how to filter events by their event id (PSI)?

Could you please provide me the way or API points if such exists?

Thank you

Regards,
Ulanbek

Hi @Ulanbek

I know this isn’t exactly what you asked but you can filter by the timeField=LAST_UPDATED which is the same as the creation date if the event wasn’t updated; however, I wasn’t able to find a way to use the same endpoint and filter by creation date.

On the other hand, the endpoint api/tracker/events/[event-id] or api/tracker/events show the creation date so you could use the filter for either the id or the events.

I understand you are refering to the /analytics endpoint because you need to get multiple metadata?

Hello Ulanbek, Hello Gassim,

I’d try something along those lines:
api/analytics/events/query/BjD13mVG82e.json?dimension=pe:2024&dimension=ou:F9w3VW1cQmb&dimension=kFb9cjO3oNs.MhLXCcvQ4JS&stage=kFb9cjO3oNs&displayProperty=NAME&totalPages=false&outputType=EVENT&id=xJXS4jkxYhT& desc=incidentdate (or lastupdated if you follow Gassim thoughts). (you can also use “asc” to order the data the other way around)

Incident date is bit of a weird thing as it’s kind of a “remainder” of the data model and is in theory used for tracker programs but it seems it works as well for event programs when it comes to API.
It also seems that incident date value (as it is for tracker programs) is by default, the creation date.

Not sure how to display it (incident date) but as far as I could test, it seemed to work for me ordering wise :slight_smile:

I hope this helps somehow,

Best regards,

Thomas

1 Like

Hi @Gassim and @Thomas_Warichet

Thank you for your support and suggestions.
Actually I have tried a lot of things, including this request:
…/api/events.json?fields=*,!lastUpdatedByUserInfo,!createdByUserInfo,!notes,!dataValues,!relationships&orgUnit=OU_UID&ouMode=DESCENDANTS&program=Program_UID

as a result we can get like this response :slight_smile: “events”: [

{
“storedBy”: “oxxxhaj”,
“dueDate”: “2024-03-06T00:00:00.000”,
“program”: “FM1NHTFOlY3”,
“event”: “rHGRpCs6lqu”,
“programStage”: “m0oAXK7x2Cl”,
“programType”: “WITH_REGISTRATION”,
“orgUnit”: “cNQIdAH2q6S”,
“enrollment”: “oNyxXmDSZhQ”,
“trackedEntityInstance”: “NCpGaHK4a3n”,
“enrollmentStatus”: “ACTIVE”,
“eventDate”: “2024-03-06T00:00:00.000”,
“orgUnitName”: “Association of PLWHA”,
“status”: “COMPLETED”,
“attributeCategoryOptions”: “xYerKDKCefk”,
“lastUpdated”: “2024-06-12T12:34:48.690”,
“created”: “2024-05-28T22:05:22.314”,
“completedDate”: “2024-05-28T22:05:22.314”,
“followup”: false,
“deleted”: false,
“attributeOptionCombo”: “HllvX50cXC0”
},

But the thing is you can’t filter events by the field CREATED

so if I could filter it just by this field or use it as timeField this could solve the problem. this parameter accepts only EVENT_DATE | SCHEDULED_DATE | < Attribute ID > | < Data element ID >.
My attempt to use &timeField=CREATED&startDate=2024-05-01&endDate=2024-05-31 resulted an empty set of events.

Yes, @Gassim I 'm trying to get first all events in that time period, and on the time of my request I should know the ID’s of that events.

@Thomas_Warichet you are right - the INCIDENT_DATE is not reliable , therefore had to create a direct sqlView request to the analytics tables :frowning:

Maybe developers will take this into consideration and will extend API point?

Thank you
Regards,
Ulanbek