Class: Spree::Api::V3::Admin::WebhookEndpointsController

Inherits:
ResourceController show all
Defined in:
app/controllers/spree/api/v3/admin/webhook_endpoints_controller.rb

Overview

Admin API for outbound webhook endpoints — CRUD plus the three endpoint-scoped actions the legacy admin had (send_test, enable, disable).

Constant Summary

Constants included from ScopedAuthorization

ScopedAuthorization::READ_ACTIONS

Constants inherited from BaseController

BaseController::RATE_LIMIT_RESPONSE

Constants included from Idempotent

Idempotent::IDEMPOTENCY_HEADER, Idempotent::IDEMPOTENCY_TTL, Idempotent::MAX_KEY_LENGTH, Idempotent::MUTATING_METHODS

Constants included from ErrorHandler

ErrorHandler::ERROR_CODES

Constants included from JwtAuthentication

JwtAuthentication::JWT_AUDIENCE_ADMIN, JwtAuthentication::JWT_AUDIENCE_STORE, JwtAuthentication::JWT_ISSUER, JwtAuthentication::USER_TYPE_ADMIN, JwtAuthentication::USER_TYPE_CUSTOMER

Instance Method Summary collapse

Methods inherited from ResourceController

#create, #destroy, #index, #show, #update

Methods included from Spree::Api::V3::ApiKeyAuthentication

#authenticate_api_key!, #authenticate_secret_key!

Methods included from JwtAuthentication

#authenticate_user, #require_authentication!

Instance Method Details

#disableHash

PATCH /api/v3/admin/webhook_endpoints/:id/disable

Manual disable — separate from the auto-disable threshold so the caller can pause an endpoint without waiting for failures.

Parameters:

  • reason (String)

    optional human-readable reason; defaults to ‘“Manually disabled”` when blank.

Returns:

  • (Hash)

    the serialized WebhookEndpoint.



46
47
48
49
50
51
52
# File 'app/controllers/spree/api/v3/admin/webhook_endpoints_controller.rb', line 46

def disable
  @resource = find_resource
  authorize!(:update, @resource)

  @resource.disable!(reason: params[:reason].presence || 'Manually disabled', notify: false)
  render json: serialize_resource(@resource)
end

#enableHash

PATCH /api/v3/admin/webhook_endpoints/:id/enable

Re-enables an endpoint that was auto-disabled after repeated failures.

Returns:

  • (Hash)

    the serialized WebhookEndpoint.



30
31
32
33
34
35
36
# File 'app/controllers/spree/api/v3/admin/webhook_endpoints_controller.rb', line 30

def enable
  @resource = find_resource
  authorize!(:update, @resource)

  @resource.enable!
  render json: serialize_resource(@resource)
end

#send_testHash

POST /api/v3/admin/webhook_endpoints/:id/send_test

Fires a synthetic ‘webhook.test` delivery so admins can verify the endpoint is reachable + their signature-verification code works.

Returns:

  • (Hash)

    the serialized WebhookDelivery, HTTP 201.



17
18
19
20
21
22
23
# File 'app/controllers/spree/api/v3/admin/webhook_endpoints_controller.rb', line 17

def send_test
  @resource = find_resource
  authorize!(:update, @resource)

  delivery = @resource.send_test!
  render json: Spree.api.admin_webhook_delivery_serializer.new(delivery).to_h, status: :created
end