mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Make sure that TrelloTrigger-Node reuse existing webhooks
This commit is contained in:
parent
1e0c5820aa
commit
bd1a79f69a
|
@ -75,31 +75,26 @@ export class TrelloTrigger implements INodeType {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
|
||||||
|
|
||||||
if (webhookData.webhookId === undefined) {
|
|
||||||
// No webhook id is set so no webhook can exist
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const credentials = this.getCredentials('trelloApi');
|
const credentials = this.getCredentials('trelloApi');
|
||||||
|
|
||||||
if (credentials === undefined) {
|
if (credentials === undefined) {
|
||||||
throw new Error('No credentials got returned!');
|
throw new Error('No credentials got returned!');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Webhook got created before so check if it still exists
|
// Check all the webhooks which exist already if it is identical to the
|
||||||
const endpoint = `tokens/${credentials.apiToken}/webhooks/${webhookData.webhookId}`;
|
// one that is supposed to get created.
|
||||||
|
const endpoint = `tokens/${credentials.apiToken}/webhooks`;
|
||||||
|
|
||||||
const responseData = await apiRequest.call(this, 'GET', endpoint, {});
|
const responseData = await apiRequest.call(this, 'GET', endpoint, {});
|
||||||
|
|
||||||
if (responseData.data === undefined) {
|
const idModel = this.getNodeParameter('id') as string;
|
||||||
return false;
|
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||||
}
|
|
||||||
|
|
||||||
for (const existingData of responseData.data) {
|
for (const webhook of responseData) {
|
||||||
if (existingData.id === webhookData.webhookId) {
|
if (webhook.idModel === idModel && webhook.callbackURL === webhookUrl) {
|
||||||
// The webhook exists already
|
// Set webhook-id to be sure that it can be deleted
|
||||||
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
webhookData.webhookId = webhook.id as string;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue