Skip to content

Commit e63313b

Browse files
committed
feat: update webhook behaviour
1 parent e4d78de commit e63313b

File tree

3 files changed

+49
-32
lines changed

3 files changed

+49
-32
lines changed

Diff for: nodes/ShopwareAdminTriggerNode/ShopwareAdminTriggerNode.node.ts

+46-29
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,37 @@ export class ShopwareAdminTriggerNode implements INodeType {
6969
webhookMethods = {
7070
default: {
7171
async checkExists(this: IHookFunctions): Promise<boolean> {
72-
const webhookData = this.getWorkflowStaticData('node');
73-
74-
if (webhookData.webhookId === undefined) {
75-
return false;
76-
}
77-
78-
try {
79-
await axios({
80-
...(await authenticate.call(this)),
81-
url: `/webhook/${webhookData.webhookId}`,
82-
method: 'GET',
83-
});
84-
} catch (error) {
72+
const response = await axios({
73+
...(await authenticate.call(this)),
74+
url: `/search/webhook`,
75+
method: 'POST',
76+
data: {
77+
page: 1,
78+
limit: 100,
79+
filter: [
80+
{
81+
type: 'equals',
82+
field: 'name',
83+
value: `n8n-${this.getNode().id}`,
84+
},
85+
],
86+
},
87+
});
88+
89+
if (response.data.total === 0) {
8590
return false;
8691
}
8792

8893
return true;
8994
},
9095
async create(this: IHookFunctions): Promise<boolean> {
9196
const webhookUrl = this.getNodeWebhookUrl('default');
92-
const webhookData = this.getWorkflowStaticData('node');
9397

9498
const eventName = this.getNodeParameter('eventName') as string;
9599
const onlyLiveVersion = this.getNodeParameter('onlyLiveVersion') as boolean;
96100

97101
try {
98-
const result = await axios({
102+
await axios({
99103
...(await authenticate.call(this)),
100104
url: '/webhook',
101105
method: 'POST',
@@ -106,29 +110,42 @@ export class ShopwareAdminTriggerNode implements INodeType {
106110
onlyLiveVersion,
107111
},
108112
});
109-
110-
webhookData.webhookId = result.data.id;
111113
} catch (error) {
112114
return false;
113115
}
114116

115117
return true;
116118
},
117119
async delete(this: IHookFunctions): Promise<boolean> {
118-
const webhookData = this.getWorkflowStaticData('node');
119-
120-
try {
121-
await axios({
122-
...(await authenticate.call(this)),
123-
url: `/webhook/${webhookData.webhookId}`,
124-
method: 'DELETE',
125-
});
126-
} catch (error) {
127-
return false;
120+
const response = await axios({
121+
...(await authenticate.call(this)),
122+
url: `/search/webhook`,
123+
method: 'POST',
124+
data: {
125+
page: 1,
126+
limit: 100,
127+
filter: [
128+
{
129+
type: 'equals',
130+
field: 'name',
131+
value: `n8n-${this.getNode().id}`,
132+
},
133+
],
134+
},
135+
});
136+
137+
for (const webhookData of response.data.data) {
138+
try {
139+
await axios({
140+
...(await authenticate.call(this)),
141+
url: `/webhook/${webhookData.id}`,
142+
method: 'DELETE',
143+
});
144+
} catch (error) {
145+
return false;
146+
}
128147
}
129148

130-
delete webhookData.webhookId;
131-
132149
return true;
133150
},
134151
},

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@c0d3bl1ck/n8n-nodes-shopware",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"description": "Community nodes to connect Shopware 6 with n8n.",
55
"keywords": [
66
"n8n-community-node-package"

0 commit comments

Comments
 (0)