Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Strava Trigger Node): Fix issue with webhook not being deleted #11226

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/nodes-base/nodes/Strava/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ export async function stravaApiRequest(

if (this.getNode().type.includes('Trigger') && resource.includes('/push_subscriptions')) {
const credentials = await this.getCredentials('stravaOAuth2Api');
if (method === 'GET') {
if (method === 'GET' || method === 'DELETE') {
qs.client_id = credentials.clientId;
qs.client_secret = credentials.clientSecret;
} else {
body.client_id = credentials.clientId;
body.client_secret = credentials.clientSecret;
}

return await this.helpers?.request(options);
} else {
return await this.helpers.requestOAuth2.call(this, 'stravaOAuth2Api', options, {
Expand Down
10 changes: 5 additions & 5 deletions packages/nodes-base/nodes/Strava/StravaTrigger.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class StravaTrigger implements INodeType {
default: false,
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
description:
'Strava allows just one subscription at all times. If you want to delete the current subscription to make room for a new subcription with the current parameters, set this parameter to true. Keep in mind this is a destructive operation.',
'Strava allows just one subscription at all times. If you want to delete the current subscription to make room for a new subscription with the current parameters, set this parameter to true. Keep in mind this is a destructive operation.',
},
],
},
Expand Down Expand Up @@ -155,9 +155,8 @@ export class StravaTrigger implements INodeType {
try {
responseData = await stravaApiRequest.call(this, 'POST', endpoint, body);
} catch (error) {
const apiErrorResponse = error.cause.response;
if (apiErrorResponse?.body?.errors) {
const errors = apiErrorResponse.body.errors;
if (error?.cause?.error) {
const errors = error?.cause?.error?.errors;
for (error of errors) {
// if there is a subscription already created
if (error.resource === 'PushSubscription' && error.code === 'already exists') {
Expand All @@ -177,6 +176,7 @@ export class StravaTrigger implements INodeType {
'DELETE',
`/push_subscriptions/${webhooks[0].id}`,
);

// now there is room create a subscription with the n8n data
const requestBody = {
callback_url: webhookUrl,
Expand All @@ -190,7 +190,7 @@ export class StravaTrigger implements INodeType {
requestBody,
);
} else {
error.message = `A subscription already exists [${webhooks[0].callback_url}]. If you want to delete this subcription and create a new one with the current parameters please go to options and set delete if exist to true`;
error.message = `A subscription already exists [${webhooks[0].callback_url}]. If you want to delete this subscription and create a new one with the current parameters please go to options and set delete if exist to true`;
throw error;
}
}
Expand Down
Loading