{"record":{"id":"9f6292db70f5d7ac","repo":"ComposioHQ/composio","slug":"a-non-empty-userid-is-required-to-create-a-trigger","errorCode":null,"errorMessage":"A non-empty userId is required to create a trigger","messagePattern":"A non-empty userId is required to create a trigger","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"ts/packages/core/src/models/Triggers.ts","lineNumber":332,"sourceCode":"  }\n\n  /**\n   * Create a new trigger instance for a user\n   * If the connected account id is not provided, the first connected account for the user and toolkit will be used\n   *\n   * @param {string} userId - The user id of the trigger instance\n   * @param {string} slug - The slug of the trigger instance\n   * @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance\n   * @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance\n   */\n  async create(\n    userId: string,\n    slug: string,\n    body?: TriggerInstanceUpsertParams,\n    requestOptions?: ComposioRequestOptions\n  ): Promise<TriggerInstanceUpsertResponse> {\n    if (!userId?.trim()) {\n      throw new ValidationError(`A non-empty userId is required to create a trigger`);\n    }\n\n    const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body ?? {});\n\n    if (!parsedBody.success) {\n      throw new ValidationError(`Invalid parameters passed to create trigger`, {\n        cause: parsedBody.error,\n      });\n    }\n\n    // Validate the trigger slug up-front so callers get a clear client-side\n    // `ComposioTriggerTypeNotFoundError`. The Python SDK mirrors this behavior.\n    try {\n      await this.getType(slug, requestOptions);\n    } catch (error) {\n      // The trigger types endpoint returns 400 (not 404) for an unknown slug.\n      if (error instanceof APIError && (error.status === 400 || error.status === 404)) {\n        throw new ComposioTriggerTypeNotFoundError(`Trigger type ${slug} not found`, {","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/ts/packages/core/src/models/Triggers.ts#L314-L350","documentation":"ValidationError('A non-empty userId is required to create a trigger') is thrown by Triggers.create when userId is undefined, null, or whitespace-only (checked via !userId?.trim()). Trigger instances are scoped per user, so this guard fires first — before body schema validation and any network call. Note it carries no cause.","triggerScenarios":"Calling triggers.create(userId, slug, body) with userId that is undefined, '', or '   '.","commonSituations":"Wrong argument order (passing slug first); userId loaded from an unset session/env variable; refactors renaming the user-id variable leaving undefined; background jobs where the user context was lost.","solutions":["Pass a real non-empty user identifier as the first argument","Verify argument order: create(userId, slug, body)","Assert a non-empty user id upstream (e.g. from the auth session) before creating triggers"],"exampleFix":"// before\nawait triggers.create('', 'github_issue_opened', { triggerConfig: {...} });\n\n// after\nawait triggers.create('user_12345', 'github_issue_opened', { triggerConfig: {...} });","handlingStrategy":"type-guard","validationCode":"const userId = session.user?.id ?? '';\nif (!userId.trim()) throw new Error('Cannot create trigger: no authenticated user');\nawait triggers.create(userId, slug, body);","typeGuard":"const isNonEmptyUserId = (id: unknown): id is string =>\n  typeof id === 'string' && id.trim().length > 0;","tryCatchPattern":"try {\n  await triggers.create(userId, slug, body);\n} catch (e) {\n  if (e instanceof ValidationError && /non-empty userId/.test(e.message)) {\n    // re-authenticate or skip trigger creation for anonymous users\n  }\n}","preventionTips":["Assert a non-empty user id before per-user trigger creation","Check argument order: (userId, slug, body)","Type the call so an undefined userId fails at compile time"],"tags":["composio","triggers","user-id","validation","typescript"],"backgroundTag":"missing-required-parameter","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}