Skip to content

Latest commit

 

History

History
324 lines (237 loc) · 21.3 KB

File metadata and controls

324 lines (237 loc) · 21.3 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

using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;

var sdk = new Client(security: new Security() {
    AdvancedAccessToken = "<YOUR_BEARER_TOKEN_HERE>",
});

var res = await sdk.Webhooks.CreateAsync(
    idempotencyKey: "123e4567-e89b-12d3-a456-426",
    requestBody: new CreateWebhookRequestBody() {
        Name = "Webhook #1",
        Url = "https://mollie.com/",
        EventTypesList = EventTypesList.CreateWebhookEventTypes(
            WebhookEventTypes.PaymentLinkPaid
        ),
        Testmode = false,
    }
);

// handle response

Parameters

Parameter Type Required Description Example
IdempotencyKey string ➖ A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
RequestBody CreateWebhookRequestBody ➖ N/A

Response

CreateWebhookResponse

Errors

Error Type Status Code Content Type
Mollie.Models.Errors.ErrorResponse 422, 429 application/hal+json
Mollie.Models.Errors.APIException 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

using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;

var sdk = new Client(
    testmode: false,
    security: new Security() {
        AdvancedAccessToken = "<YOUR_BEARER_TOKEN_HERE>",
    }
);

ListWebhooksRequest req = new ListWebhooksRequest() {
    From = "hook_B2EyhTH5N4KWUnoYPcgiH",
    Limit = 50,
    Sort = Sorting.Desc,
    EventTypes = WebhookEventTypes.PaymentLinkPaid,
    IdempotencyKey = "123e4567-e89b-12d3-a456-426",
};

ListWebhooksResponse? res = await sdk.Webhooks.ListAsync(req);

while(res != null)
{
    // handle items

    res = await res.Next!();
}

Parameters

Parameter Type Required Description
request ListWebhooksRequest ✔️ The request object to use for the request.

Response

ListWebhooksResponse

Errors

Error Type Status Code Content Type
Mollie.Models.Errors.ErrorResponse 400, 429 application/hal+json
Mollie.Models.Errors.APIException 4XX, 5XX */*

Update

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

Example Usage

using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;

var sdk = new Client(security: new Security() {
    AdvancedAccessToken = "<YOUR_BEARER_TOKEN_HERE>",
});

var res = await sdk.Webhooks.UpdateAsync(
    webhookId: "hook_1234567890",
    idempotencyKey: "123e4567-e89b-12d3-a456-426",
    requestBody: new UpdateWebhookRequestBody() {
        Name = "Webhook #1",
        Url = "https://mollie.com/",
        EventTypes = EventTypes.CreateWebhookEventTypes(
            WebhookEventTypes.PaymentLinkPaid
        ),
        Testmode = false,
    }
);

// handle response

Parameters

Parameter Type Required Description Example
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 UpdateWebhookRequestBody ➖ N/A

Response

UpdateWebhookResponse

Errors

Error Type Status Code Content Type
Mollie.Models.Errors.ErrorResponse 404, 422, 429 application/hal+json
Mollie.Models.Errors.APIException 4XX, 5XX */*

Get

Retrieve a single webhook object by its ID.

Example Usage: get-webhook-200

using Mollie;
using Mollie.Models.Components;

var sdk = new Client(
    testmode: false,
    security: new Security() {
        AdvancedAccessToken = "<YOUR_BEARER_TOKEN_HERE>",
    }
);

var res = await sdk.Webhooks.GetAsync(
    webhookId: "hook_1234567890",
    idempotencyKey: "123e4567-e89b-12d3-a456-426"
);

// handle response

Example Usage: get-webhook-200-1

using Mollie;
using Mollie.Models.Components;

var sdk = new Client(
    testmode: false,
    security: new Security() {
        AdvancedAccessToken = "<YOUR_BEARER_TOKEN_HERE>",
    }
);

var res = await sdk.Webhooks.GetAsync(
    webhookId: "hook_1234567890",
    idempotencyKey: "123e4567-e89b-12d3-a456-426"
);

// handle response

Parameters

Parameter Type Required Description Example
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

Response

GetWebhookResponse

Errors

Error Type Status Code Content Type
Mollie.Models.Errors.ErrorResponse 404, 422, 429 application/hal+json
Mollie.Models.Errors.APIException 4XX, 5XX */*

Delete

Delete a single webhook object by its webhook ID.

Example Usage

using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;

var sdk = new Client(security: new Security() {
    AdvancedAccessToken = "<YOUR_BEARER_TOKEN_HERE>",
});

var res = await sdk.Webhooks.DeleteAsync(
    webhookId: "hook_1234567890",
    idempotencyKey: "123e4567-e89b-12d3-a456-426",
    requestBody: new DeleteWebhookRequestBody() {
        Testmode = false,
    }
);

// handle response

Parameters

Parameter Type Required Description Example
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 DeleteWebhookRequestBody ➖ N/A

Response

DeleteWebhookResponse

Errors

Error Type Status Code Content Type
Mollie.Models.Errors.ErrorResponse 404, 422, 429 application/hal+json
Mollie.Models.Errors.APIException 4XX, 5XX */*

Test

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

Example Usage

using Mollie;
using Mollie.Models.Components;
using Mollie.Models.Requests;

var sdk = new Client(security: new Security() {
    AdvancedAccessToken = "<YOUR_BEARER_TOKEN_HERE>",
});

var res = await sdk.Webhooks.TestAsync(
    webhookId: "hook_1234567890",
    idempotencyKey: "123e4567-e89b-12d3-a456-426",
    requestBody: new TestWebhookRequestBody() {
        Testmode = false,
    }
);

// handle response

Parameters

Parameter Type Required Description Example
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 TestWebhookRequestBody ➖ N/A

Response

TestWebhookResponse

Errors

Error Type Status Code Content Type
Mollie.Models.Errors.ErrorResponse 404, 422, 429 application/hal+json
Mollie.Models.Errors.APIException 4XX, 5XX */*