There is an additional step after getting events from the webhook, I have to grab manually what has changed in the targeted resource, that should return an array of change events.
What I want to do now is to store the value of a marker provided by the last execution of this retrieval so that the next time I retrieve the dataset it will ignore all entries before the marker.
Is there a built-in feature to implement such a flow?
thanks for your quick reply @jan
I already use it in webhookMethods.default.checkExists and webhookMethods.default.create, but I could not make it work within webhook function.
I tried something like this, I checked in database but the value has not been stored
const workflowData = this.getWorkflowStaticData('node');
workflowData.lastChangeToken = "a string here"
yes, workflow succeeds
what do you mean by manually via editor-UI, webhook Test Mode?
anyway for both it’s not stored, I explictly activated the workflow to have it in production mode. Still same result.
What is the flow behind webhookData.<some-property> = value, where can I find it.
I just noticed that this statement seems working like a charm within webhookMethods functions but not in webhook implementation
I’d just like to know wether the scope of execution of this statement matters. I noticed that in the webhook method this is as IWebhookFunctions and in webhooks.<name>.<method> it’s a IHookFunctions
So now I’m wondering if the concrete object returned by this.getWorkflowStaticData('node') on both scopes are the same. I don’t even know if that make sense actually.
Anyway here is the code:
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
const credentials = this.getCredentials(credentialName);
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
const webhookData = this.getWorkflowStaticData('node') as IDataObject;
const listEvents = await customApi.retrieveListEvent();
if (listEvents.length > 0) {
// the issue is that the value I set here is not persiting
webhookData.lastChangeToken = listEvents.pop().ChangeToken.StringValue as string
}
// ... return statement
}
@jan I’m wondering if I shouldn’t call a workflow save here to persist what has changed in webhookData. Is there a common way to do that witin this webhook function scope?
Sorry @irzhywau had to do some testing and check the code. You are right there was a bug and it did not get saved. I just fixed it and will release it with the next version. Will update here once released.