MCPcopy Index your code
hub / github.com/simstudioai/sim / createSubscription

Function createSubscription

apps/sim/lib/webhooks/providers/airtable.ts:441–569  ·  view source on GitHub ↗
({
    webhook: webhookRecord,
    workflow,
    userId,
    requestId,
  }: SubscriptionContext)

Source from the content-addressed store, hash-verified

439
440export const airtableHandler: WebhookProviderHandler = {
441 async createSubscription({
442 webhook: webhookRecord,
443 workflow,
444 userId,
445 requestId,
446 }: SubscriptionContext): Promise<SubscriptionResult | undefined> {
447 try {
448 const { path, providerConfig } = webhookRecord as Record<string, unknown>
449 const config = (providerConfig as Record<string, unknown>) || {}
450 const { baseId, tableId, includeCellValuesInFieldIds, credentialId } = config as {
451 baseId?: string
452 tableId?: string
453 includeCellValuesInFieldIds?: string
454 credentialId?: string
455 }
456
457 if (!baseId || !tableId) {
458 logger.warn(`[${requestId}] Missing baseId or tableId for Airtable webhook creation.`, {
459 webhookId: webhookRecord.id,
460 })
461 throw new Error(
462 'Base ID and Table ID are required to create Airtable webhook. Please provide valid Airtable base and table IDs.'
463 )
464 }
465
466 const baseIdValidation = validateAirtableId(baseId, 'app', 'baseId')
467 if (!baseIdValidation.isValid) {
468 throw new Error(baseIdValidation.error)
469 }
470
471 const tableIdValidation = validateAirtableId(tableId, 'tbl', 'tableId')
472 if (!tableIdValidation.isValid) {
473 throw new Error(tableIdValidation.error)
474 }
475
476 const credentialOwner = credentialId
477 ? await getCredentialOwner(credentialId, requestId)
478 : null
479 const accessToken = credentialId
480 ? credentialOwner
481 ? await refreshAccessTokenIfNeeded(
482 credentialOwner.accountId,
483 credentialOwner.userId,
484 requestId
485 )
486 : null
487 : await getOAuthToken(userId, 'airtable')
488 if (!accessToken) {
489 logger.warn(
490 `[${requestId}] Could not retrieve Airtable access token for user ${userId}. Cannot create webhook in Airtable.`
491 )
492 throw new Error(
493 'Airtable account connection required. Please connect your Airtable account in the trigger configuration and try again.'
494 )
495 }
496
497 const notificationUrl = `${getBaseUrl()}/api/webhooks/trigger/${path}`
498

Callers

nothing calls this directly

Calls 8

validateAirtableIdFunction · 0.90
getCredentialOwnerFunction · 0.90
getOAuthTokenFunction · 0.90
getBaseUrlFunction · 0.90
errorMethod · 0.80
infoMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected