Callback Filtering
What is Callback Filtering
When a hook with filter attribute is created, you can filter out a callback if its event payload does not match the filter attribute. You can find a property to filter from the payload section for any Supported Events. For example, filter attribute $[?(@.ext==’txt’)] can be used to filter dm.version.added callbacks based on the extension of a file.
Hook filter attribute is defined in JsonPath format, check it out for for more details about the syntax of JsonPath expression. http://jsonpath.herokuapp.com/ can be used to test the JsonPath expressions.
Filter Formats
With the Single Filter format, you specify a single JsonPath expression in the filter field. For example: $[?(@.ext==’txt’)]
With the Multiple Filter format, you can specify a list of JsonPath expressions, all of which must be match for the hook to be triggered. There is no option for doing OR filtering. For example: [“$[?(@.sizeInBytes>=1048576)]”,”$[?(@.ext==’f3d’)]”]
Example 1
Create an dm.version.added event hook with file extension filtering:
Create a Webhook
curl -X 'POST'\
-v 'https://developer.api.autodesk.com/webhooks/v1/systems/data/events/dm.version.added/hooks'\
-H 'Content-Type: application/json'\
-H 'authorization: Bearer bNU4P0trbQKNSzxWksLPTzSbbmUz'\
-d '{
"callbackUrl": "http://bf067e05.ngrok.io/callback",
"scope": {
"folder": "urn:adsk.wipprod:fs.folder:co.wT5lCWlXSKeo3razOfHJAw"
},
"hookAttribute": {
/* Custom metadata */
"myfoo": 33,
"projectId": "someURN",
"myobject": {
"nested": true
}
},
"filter": "$[?(@.ext=='txt')]"
}'
Callback Payload
{
"version": "1.0",
"resourceUrn": "urn:adsk.wipprod:fs.file:vf.0zvdp3CoTzWDcZC_wL0kJA?version=1",
"hook": {
"system": "data",
"event": "dm.version.added",
"hookId": "1fcd3e30-9f3f-11e7-951f-0fd5337ed5ce",
"tenant": "urn:adsk.wipprod:fs.folder:co.wT5lCWlXSKeo3razOfHJAw",
"callbackUrl": "http://bf067e05.ngrok.io/callback",
"createdBy": "*************",
"createdDate": "2017-09-22T02:38:32.341+0000",
"creatorType": "Application",
"filter": "$[?(@.ext=='txt')]",
"hookAttribute": {
"myfoo": 34,
"projectId": "someURN",
"myobject": {
"nested": true
}
},
"scope": {
"folder": "urn:adsk.wipprod:fs.folder:co.wT5lCWlXSKeo3razOfHJAw"
},
"urn": "urn:adsk.webhooks:events.hook:1fcd3e30-9f3f-11e7-951f-0fd5337ed5ce",
"status": "active",
"__self__": "/systems/data/events/dm.version.added/hooks/1fcd3e30-9f3f-11e7-951f-0fd5337ed5ce"
},
"payload": {
"ext": "txt",
"modifiedTime": "2017-09-25T03:08:53+0000",
"creator": "*************",
"lineageUrn": "urn:adsk.wipprod:dm.lineage:0zvdp3CoTzWDcZC_wL0kJA",
"sizeInBytes": 36,
"hidden": false,
"indexable": true,
"project": "4f8b8b74-3853-473d-85c4-4e8a8bff885b",
"source": "urn:adsk.wipprod:fs.file:vf.0zvdp3CoTzWDcZC_wL0kJA?version=1",
"version": "1",
"user_info": {
"id": "*************"
},
"name": "dc829fc5-bd21-4444-8d8f-735ae4fe736f.txt",
"createdTime": "2017-09-06T03:08:53+0000",
"modifiedBy": "*************",
"state": "CONTENT_AVAILABLE",
"parentFolderUrn": "urn:adsk.wipprod:fs.folder:co.wT5lCWlXSKeo3razOfHJAw",
"ancestors": [
{
"urn": "urn:adsk.wipprod:fs.folder:co.woxoClweRCeMWn-HFbXGdQ",
"name": "b662c88c-85e3-45c7-a9cc-6c77a31462a4"
},
{
"urn": "urn:adsk.wipprod:fs.folder:co.XFrPsQGxRomOJzyL1-z7Tg",
"name": "292139e5-5f7f-402c-90f0-e61b53f38aad-account-root-folder"
},
{
"urn": "urn:adsk.wipprod:fs.folder:co.6a5Ylw9mRDus2bhttmH7dw",
"name": "4f8b8b74-3853-473d-85c4-4e8a8bff885b-root-folder"
},
{
"urn": "urn:adsk.wipprod:fs.folder:co.bXJiDx2ySve30xhul5Ihuw",
"name": "Project Files"
},
{
"urn": "urn:adsk.wipprod:fs.folder:co.chOa5mlkR6mjN-PEx8-r8Q",
"name": "SomeTest"
}
],
"tenant": "292139e5-5f7f-402c-90f0-e61b53f38aad"
}
}
Example 2
Create an extraction.finished event hook with status filtering:
Create a Webhook
curl -X 'POST'\
-v 'https://developer.api.autodesk.com/webhooks/v1/systems/derivative/events/extraction.finished/hooks'\
-H 'Content-Type: application/json'\
-H 'authorization: Bearer bNU4P0trbQKNSzxWksLPTzSbbmUz'\
-d '{
"callbackUrl": "http://bf067e05.ngrok.io/callback",
"scope": {
"workflow": "my-workflow-id"
},
"filter": "$[?(@.Payload.status in ['failed','timeout'])]"
}'
Callback Payload
{
"version": "1.0",
"resourceUrn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6d2htZHRlc3RzdGcvQ2FzZUlubmVyLmlwdA",
"hook": {
"hookId": "a228fb60-106b-11e8-9774-490cff0c6aae",
"tenant": "my-workflow-id",
"callbackUrl": "http://bf067e05.ngrok.io/callback",
"createdBy": "*************",
"event": "extraction.finished",
"createdDate": "2018-02-13T03:11:50.294+0000",
"system": "derivative",
"creatorType": "Application",
"status": "active",
"scope": {
"workflow": "my-workflow-id"
},
"urn": "urn:adsk.webhooks:events.hook:a228fb60-106b-11e8-9774-490cff0c6aae",
"__self__": "/systems/derivative/events/extraction.finished/hooks/a228fb60-106b-11e8-9774-490cff0c6aae"
},
"payload": {
"TimeStamp": 1513134729128,
"URN": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6d2htZHRlc3RzdGcvQ2FzZUlubmVyLmlwdA",
"EventType": "EXTRACTION_FINISHED",
"Payload": {
"status": "failed",
"scope": "7dca556c-e041-444a-91cf-cdea18a7699e",
"registerKey": []
}
}
}