Module: MailchimpAPI::Audience::Webhooks::APIs

Includes:
Pagination::ListEachItemHelper
Included in:
MailchimpAPI::Audience::Webhooks, MailchimpAPI::Audience::Webhooks
Defined in:
lib/mailchimp-api/resources/audience/webhooks.rb

Overview

Module with endpoints for Webhooks APIs

Instance Method Summary collapse

Instance Method Details

#create(list_id, query: nil, body: nil, headers: nil) ⇒ Response

Create a new webhook

Examples:

Create a webhook for subscribe events

webhooks.create('list123', body: {
  url: 'https://example.com/webhook',
  events: { subscribe: true }
})

Parameters:

  • list_id (String)

    The ID of the Mailchimp list

  • query (Hash) (defaults to: nil)

    Optional query parameters

  • body (Hash) (defaults to: nil)

    Webhook attributes

  • headers (Hash) (defaults to: nil)

    Optional request headers

Options Hash (body:):

  • :url (String)

    The URL for the webhook

  • :events (Hash)

    Events to subscribe to

Returns:

  • (Response)

    API response containing the created webhook



38
39
40
41
# File 'lib/mailchimp-api/resources/audience/webhooks.rb', line 38

def create(list_id, query: nil, body: nil, headers: nil)
  path = "/lists/#{list_id}/webhooks"
  client.post(path, query: query, body: body, headers: headers)
end

#delete(list_id, webhook_id, query: nil, body: nil, headers: nil) ⇒ Response

Delete a webhook

Examples:

Delete a webhook

webhooks.delete('list123', 'webhook456')

Parameters:

  • list_id (String)

    The ID of the Mailchimp list

  • webhook_id (String)

    The ID of the webhook to delete

  • query (Hash) (defaults to: nil)

    Optional query parameters

  • body (Hash) (defaults to: nil)

    Optional request body

  • headers (Hash) (defaults to: nil)

    Optional request headers

Returns:



66
67
68
69
# File 'lib/mailchimp-api/resources/audience/webhooks.rb', line 66

def delete(list_id, webhook_id, query: nil, body: nil, headers: nil)
  path = "/lists/#{list_id}/webhooks/#{webhook_id}"
  client.delete(path, query: query, body: body, headers: headers)
end

#each(list_id, query: nil, body: nil, headers: nil) {|Hash| ... } ⇒ Object

Iterate through all webhooks for a list

Examples:

Iterate through webhooks

webhooks.each('list123') do |webhook|
  puts webhook[:url]
end

Parameters:

  • list_id (String)

    The ID of the Mailchimp list

  • query (Hash) (defaults to: nil)

    Optional query parameters

  • body (Hash) (defaults to: nil)

    Optional request body

  • headers (Hash) (defaults to: nil)

    Optional request headers

Yields:

  • (Hash)

    Each webhook



97
98
99
# File 'lib/mailchimp-api/resources/audience/webhooks.rb', line 97

def each(list_id, query: nil, body: nil, headers: nil, &block)
  list_each_item(:webhooks, list_id, query: query, body: body, headers: headers, &block)
end

#list(list_id, query: nil, body: nil, headers: nil) ⇒ Response

List webhooks for a specific list

Examples:

Get webhooks for a list

webhooks.list('list123')

Parameters:

  • list_id (String)

    The ID of the Mailchimp list

  • query (Hash) (defaults to: nil)

    Optional query parameters

  • body (Hash) (defaults to: nil)

    Optional request body

  • headers (Hash) (defaults to: nil)

    Optional request headers

Returns:

  • (Response)

    API response containing webhooks



20
21
22
23
# File 'lib/mailchimp-api/resources/audience/webhooks.rb', line 20

def list(list_id, query: nil, body: nil, headers: nil)
  path = "/lists/#{list_id}/webhooks"
  client.get(path, query: query, body: body, headers: headers)
end

#show(list_id, webhook_id, query: nil, body: nil, headers: nil) ⇒ Response

Show details for a specific webhook

Examples:

Get details for a webhook

webhooks.show('list123', 'webhook456')

Parameters:

  • list_id (String)

    The ID of the Mailchimp list

  • webhook_id (String)

    The ID of the webhook

  • query (Hash) (defaults to: nil)

    Optional query parameters

  • body (Hash) (defaults to: nil)

    Optional request body

  • headers (Hash) (defaults to: nil)

    Optional request headers

Returns:

  • (Response)

    API response containing webhook details



52
53
54
55
# File 'lib/mailchimp-api/resources/audience/webhooks.rb', line 52

def show(list_id, webhook_id, query: nil, body: nil, headers: nil)
  path = "/lists/#{list_id}/webhooks/#{webhook_id}"
  client.get(path, query: query, body: body, headers: headers)
end

#update(list_id, webhook_id, query: nil, body: nil, headers: nil) ⇒ Response

Update a webhook

Examples:

Update webhook events

webhooks.update('list123', 'webhook456', body: {
  events: { subscribe: true, unsubscribe: true }
})

Parameters:

  • list_id (String)

    The ID of the Mailchimp list

  • webhook_id (String)

    The ID of the webhook to update

  • query (Hash) (defaults to: nil)

    Optional query parameters

  • body (Hash) (defaults to: nil)

    Updated webhook attributes

  • headers (Hash) (defaults to: nil)

    Optional request headers

Returns:

  • (Response)

    API response containing updated webhook



82
83
84
85
# File 'lib/mailchimp-api/resources/audience/webhooks.rb', line 82

def update(list_id, webhook_id, query: nil, body: nil, headers: nil)
  path = "/lists/#{list_id}/webhooks/#{webhook_id}"
  client.patch(path, query: query, body: body, headers: headers)
end