Finding deleted records

41 views
Skip to first unread message

Dennis Hevener

unread,
Nov 19, 2019, 2:35:17 PM11/19/19
to Zengine Development
Hi--

I am keeping a local SQL Server copy of some of the WizeHive tables, using the ZEngine API. 

How do I find records that have been deleted in WizeHive so that I can delete them from my local table?

Thanks,

Dennis

Anna Parks

unread,
Nov 19, 2019, 3:13:43 PM11/19/19
to Zengine Development
Hi Dennis,

If this is an occasional clean-up script you are running on a one-off basis, your best bet is to use the activity endpoint. The gets all the deleted records for a given workspace:

GET https://api.zenginehq.com/v1/activities?action=delete&workspace.id={{your workspace id}}&resource=records

If you want to do this more automatically - i.e. by listening for every time a record in a workspace (and optionally a form) is deleted, you can create a webhook like so:

POST https://api.zenginehq.com/v1/webhooks
{
 
"workspace.id": 123,
 
"includeRelated": false,
 
"resource": "records",
 
"url": "https://dennis.io/your-server-endpoint-to-delete-sql-tables"

}

The webhook will POST a payload to your specified URL that looks like this:
{
  "requestId": "5a98544b-1798-42cb-b7d3-2731e7a79d22",
  "developerMessage": "The data in the payload is an activity.",
  "webhook": {
    "id": 1
  },
  "webhookEvent": {
     "id": 2
  },
  "data": [{
    "id": 3,
    "workspace": {
      "id": 123
    },
    "resource": "records",
    "action": "delete",
    "createdByUser": {
      "id": 123
    },
    "record": {
      "id": 1,
      "workspace": {
        "id": 123
      },
      "form": {
        "id": 456
      },
      "folder": {
        "id": 0
      },
      "createdByUser": {
        "id": 123
      },
      "createdByClient": {
        "id": 80
      }
    },
    "created": "2018-03-01 19:28:10"
  }]
}


Hope this helps,

Anna

Dennis Hevener

unread,
Jun 29, 2022, 10:27:16 AM6/29/22
to Zengine Development
It time to revisit this.

As I recall, there was a phone discussion with someone at Wizehive that said the Activities endpoint did not work.  I want to see if anything has changed and if it is possible to retrieve deleted records for the past couple days.

In my experimentation, I found that if I delete a record, then do this (with the current day as the min-modified parameter):
https://api.zenginehq.com/v1/activities.json?workspace.id=9999&resource=records&min-modified=2022-06-29T00:00:00&action=delete&access_token=9999
it does indeed find my single deleted record.  However, changing the date to a few days results in a   500 code 5100 error.   I added &limit=10 & page=1 to no avail. Same thing. 

Is there any way to do what I need to do?  Right now my only known solution is to wipe everything and rebuild my SQL database, or query each record in my SQL database and see if it exists in Wizehive or not -- overhead that neither of us want.

Wes

unread,
Jul 1, 2022, 9:22:47 AM7/1/22
to Zengine Development
Dennis,
Since the activity endpoint doesn't seem to be working for this case, I would recommend taking the other advice above of using a webhook to keep your records in sync.

For existing data, you can query the form records API as you mentioned. You may not need to fetch each record one by one - you could paginate the form records endpoint to find all the records ids, then compare with your local ids to find any missing records. You could also run a form export, download the CSV file, then compare the CSV file to your data.

Dennis Hevener

unread,
Aug 11, 2022, 5:41:50 PM8/11/22
to Zengine Development
Thanks Wes.
Reply all
Reply to author
Forward
0 new messages