Skip to content

Latest commit

 

History

History
433 lines (338 loc) · 30.2 KB

File metadata and controls

433 lines (338 loc) · 30.2 KB

Webhooks

Overview

Available Operations

  • Create - Create a webhook
  • List - List all webhooks
  • Update - Update a webhook
  • Get - Get a webhook
  • Delete - Delete a webhook
  • Test - Test a webhook

Create

A webhook must have a name, an url and a list of event types. You can also create webhooks in the webhooks settings section of the Dashboard.

Example Usage

package main

import(
	"context"
	"os"
	"github.com/mollie/mollie-api-golang/models/components"
	client "github.com/mollie/mollie-api-golang"
	"github.com/mollie/mollie-api-golang/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := client.New(
        client.WithSecurity(components.Security{
            OrganizationAccessToken: client.Pointer(os.Getenv("CLIENT_ORGANIZATION_ACCESS_TOKEN")),
        }),
    )

    res, err := s.Webhooks.Create(ctx, client.Pointer("123e4567-e89b-12d3-a456-426"), &operations.CreateWebhookRequestBody{
        Name: "Webhook #1",
        URL: "https://mollie.com/",
        EventTypes: operations.CreateCreateWebhookEventTypesWebhookEventTypes(
            components.WebhookEventTypesPaymentLinkPaid,
        ),
        Testmode: client.Pointer(false),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.CreateWebhook != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
idempotencyKey *string A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
requestBody *operations.CreateWebhookRequestBody N/A
opts []operations.Option The options for this request.

Response

*operations.CreateWebhookResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 422 application/hal+json
apierrors.APIError 4XX, 5XX */*

List

Returns a paginated list of your webhooks. If no webhook endpoints are available, the resulting array will be empty. This request should never throw an error.

Example Usage

package main

import(
	"context"
	"os"
	"github.com/mollie/mollie-api-golang/models/components"
	client "github.com/mollie/mollie-api-golang"
	"github.com/mollie/mollie-api-golang/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := client.New(
        client.WithTestmode(false),
        client.WithSecurity(components.Security{
            OrganizationAccessToken: client.Pointer(os.Getenv("CLIENT_ORGANIZATION_ACCESS_TOKEN")),
        }),
    )

    res, err := s.Webhooks.List(ctx, operations.ListWebhooksRequest{
        From: client.Pointer("hook_B2EyhTH5N4KWUnoYPcgiH"),
        Limit: client.Pointer[int64](50),
        Sort: components.SortingDesc.ToPointer(),
        EventTypes: components.WebhookEventTypesPaymentLinkPaid.ToPointer(),
        IdempotencyKey: client.Pointer("123e4567-e89b-12d3-a456-426"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Object != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
request operations.ListWebhooksRequest ✔️ The request object to use for the request.
opts []operations.Option The options for this request.

Response

*operations.ListWebhooksResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 400 application/hal+json
apierrors.APIError 4XX, 5XX */*

Update

Updates the webhook. You may edit the name, url and the list of subscribed event types.

Example Usage

package main

import(
	"context"
	"os"
	"github.com/mollie/mollie-api-golang/models/components"
	client "github.com/mollie/mollie-api-golang"
	"github.com/mollie/mollie-api-golang/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := client.New(
        client.WithSecurity(components.Security{
            OrganizationAccessToken: client.Pointer(os.Getenv("CLIENT_ORGANIZATION_ACCESS_TOKEN")),
        }),
    )

    res, err := s.Webhooks.Update(ctx, "hook_1234567890", client.Pointer("123e4567-e89b-12d3-a456-426"), &operations.UpdateWebhookRequestBody{
        Name: client.Pointer("Webhook #1"),
        URL: client.Pointer("https://mollie.com/"),
        EventTypes: client.Pointer(operations.CreateUpdateWebhookEventTypesWebhookEventTypes(
            components.WebhookEventTypesPaymentLinkPaid,
        )),
        Testmode: client.Pointer(false),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.EntityWebhook != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
webhookID string ✔️ Provide the ID of the related webhook. hook_1234567890
idempotencyKey *string A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
requestBody *operations.UpdateWebhookRequestBody N/A
opts []operations.Option The options for this request.

Response

*operations.UpdateWebhookResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 404, 422 application/hal+json
apierrors.APIError 4XX, 5XX */*

Get

Retrieve a single webhook object by its ID.

Example Usage: get-webhook-200

package main

import(
	"context"
	"os"
	"github.com/mollie/mollie-api-golang/models/components"
	client "github.com/mollie/mollie-api-golang"
	"log"
)

func main() {
    ctx := context.Background()

    s := client.New(
        client.WithTestmode(false),
        client.WithSecurity(components.Security{
            OrganizationAccessToken: client.Pointer(os.Getenv("CLIENT_ORGANIZATION_ACCESS_TOKEN")),
        }),
    )

    res, err := s.Webhooks.Get(ctx, "hook_1234567890", client.Pointer("123e4567-e89b-12d3-a456-426"))
    if err != nil {
        log.Fatal(err)
    }
    if res.EntityWebhook != nil {
        // handle response
    }
}

Example Usage: get-webhook-200-1

package main

import(
	"context"
	"os"
	"github.com/mollie/mollie-api-golang/models/components"
	client "github.com/mollie/mollie-api-golang"
	"log"
)

func main() {
    ctx := context.Background()

    s := client.New(
        client.WithTestmode(false),
        client.WithSecurity(components.Security{
            OrganizationAccessToken: client.Pointer(os.Getenv("CLIENT_ORGANIZATION_ACCESS_TOKEN")),
        }),
    )

    res, err := s.Webhooks.Get(ctx, "hook_1234567890", client.Pointer("123e4567-e89b-12d3-a456-426"))
    if err != nil {
        log.Fatal(err)
    }
    if res.EntityWebhook != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
webhookID string ✔️ Provide the ID of the related webhook. hook_1234567890
testmode *bool You can enable test mode by setting the testmode query parameter to true.

Test entities cannot be retrieved when the endpoint is set to live mode, and vice versa.
idempotencyKey *string A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
opts []operations.Option The options for this request.

Response

*operations.GetWebhookResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 404, 422 application/hal+json
apierrors.APIError 4XX, 5XX */*

Delete

Delete a single webhook object by its webhook ID.

Example Usage

package main

import(
	"context"
	"os"
	"github.com/mollie/mollie-api-golang/models/components"
	client "github.com/mollie/mollie-api-golang"
	"github.com/mollie/mollie-api-golang/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := client.New(
        client.WithSecurity(components.Security{
            OrganizationAccessToken: client.Pointer(os.Getenv("CLIENT_ORGANIZATION_ACCESS_TOKEN")),
        }),
    )

    res, err := s.Webhooks.Delete(ctx, "hook_1234567890", client.Pointer("123e4567-e89b-12d3-a456-426"), &operations.DeleteWebhookRequestBody{
        Testmode: client.Pointer(false),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
webhookID string ✔️ Provide the ID of the related webhook. hook_1234567890
idempotencyKey *string A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
requestBody *operations.DeleteWebhookRequestBody N/A
opts []operations.Option The options for this request.

Response

*operations.DeleteWebhookResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 404, 422 application/hal+json
apierrors.APIError 4XX, 5XX */*

Test

Sends a test event to the webhook to verify the endpoint is working as expected.

Example Usage

package main

import(
	"context"
	"os"
	"github.com/mollie/mollie-api-golang/models/components"
	client "github.com/mollie/mollie-api-golang"
	"github.com/mollie/mollie-api-golang/models/operations"
	"log"
)

func main() {
    ctx := context.Background()

    s := client.New(
        client.WithSecurity(components.Security{
            OrganizationAccessToken: client.Pointer(os.Getenv("CLIENT_ORGANIZATION_ACCESS_TOKEN")),
        }),
    )

    res, err := s.Webhooks.Test(ctx, "hook_1234567890", client.Pointer("123e4567-e89b-12d3-a456-426"), &operations.TestWebhookRequestBody{
        Testmode: client.Pointer(false),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
webhookID string ✔️ Provide the ID of the related webhook. hook_1234567890
idempotencyKey *string A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
requestBody *operations.TestWebhookRequestBody N/A
opts []operations.Option The options for this request.

Response

*operations.TestWebhookResponse, error

Errors

Error Type Status Code Content Type
apierrors.ErrorResponse 404, 422 application/hal+json
apierrors.APIError 4XX, 5XX */*