mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -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;
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
// Webhook got created before so check if it still exists
|
||||
const endpoint = `tokens/${credentials.apiToken}/webhooks/${webhookData.webhookId}`;
|
||||
// Check all the webhooks which exist already if it is identical to the
|
||||
// one that is supposed to get created.
|
||||
const endpoint = `tokens/${credentials.apiToken}/webhooks`;
|
||||
|
||||
const responseData = await apiRequest.call(this, 'GET', endpoint, {});
|
||||
|
||||
if (responseData.data === undefined) {
|
||||
return false;
|
||||
}
|
||||
const idModel = this.getNodeParameter('id') as string;
|
||||
const webhookUrl = this.getNodeWebhookUrl('default');
|
||||
|
||||
for (const existingData of responseData.data) {
|
||||
if (existingData.id === webhookData.webhookId) {
|
||||
// The webhook exists already
|
||||
for (const webhook of responseData) {
|
||||
if (webhook.idModel === idModel && webhook.callbackURL === webhookUrl) {
|
||||
// Set webhook-id to be sure that it can be deleted
|
||||
const webhookData = this.getWorkflowStaticData('node');
|
||||
webhookData.webhookId = webhook.id as string;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue