Skip to content
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
6 changes: 6 additions & 0 deletions apps/sim/app/api/webhooks/trigger/[path]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
checkWebhookPreprocessing,
findWebhookAndWorkflow,
handleProviderChallenges,
handleProviderReachabilityTest,
parseWebhookBody,
queueWebhookExecution,
verifyProviderAuth,
Expand Down Expand Up @@ -123,6 +124,11 @@ export async function POST(
return authError
}

const reachabilityResponse = handleProviderReachabilityTest(foundWebhook, body, requestId)
if (reachabilityResponse) {
return reachabilityResponse
}

let preprocessError: NextResponse | null = null
try {
preprocessError = await checkWebhookPreprocessing(foundWorkflow, foundWebhook, requestId)
Expand Down
28 changes: 28 additions & 0 deletions apps/sim/lib/webhooks/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,34 @@ export async function handleProviderChallenges(
return null
}

/**
* Handle provider-specific reachability tests that occur AFTER webhook lookup.
*
* @param webhook - The webhook record from the database
* @param body - The parsed request body
* @param requestId - Request ID for logging
* @returns NextResponse if this is a verification request, null to continue normal flow
*/
export function handleProviderReachabilityTest(
webhook: any,
body: any,
requestId: string
): NextResponse | null {
const provider = webhook?.provider

if (provider === 'grain') {
const isVerificationRequest = !body || Object.keys(body).length === 0 || !body.type
if (isVerificationRequest) {
logger.info(
`[${requestId}] Grain reachability test detected - returning 200 for webhook verification`
)
return NextResponse.json({ status: 'ok', message: 'Webhook endpoint verified' })
}
}

return null
}

export async function findWebhookAndWorkflow(
options: WebhookProcessorOptions
): Promise<{ webhook: any; workflow: any } | null> {
Expand Down