authorizeCurrentWorkspace( $request, 'manageWebhooks', 'Not authorized to manage webhooks.', ); if (! $workspace instanceof Workspace) { return $workspace; } $validated = $request->validate(UpdateWebhookRequest::rules()); $webhook = $this->webhookInWorkspace($workspace, data_get($validated, 'webhook_id')); if (! $webhook instanceof Webhook) { return $webhook; } try { $webhook = UpdateWebhook::execute( $webhook, Arr::except($validated, ['webhook_id']), $this->webhooks, ); } catch (RuntimeException $e) { return Response::error($e->getMessage()); } return Response::structured((new WebhookResource($webhook))->resolve()); } /** * @return array */ public function schema(JsonSchema $schema): array { return [ 'webhook_id' => $schema->string()->required()->description('The webhook ID.'), 'endpoint' => $schema->string()->description('New public URL. Private or local addresses are rejected. Omitted fields are left unchanged.'), 'events' => $schema->array() ->items($schema->string()->enum(array_column(EventType::cases(), 'value'))) ->description('Replacement event list. Must contain at least one event when provided.'), 'status' => $schema->string() ->enum([Status::Enabled->value, Status::Disabled->value]) ->description('Set to enabled or disabled. Paused webhooks can only be re-enabled, not set to paused.'), ]; } }