Skip to content

Latest commit

 

History

History
412 lines (304 loc) · 25.9 KB

File metadata and controls

412 lines (304 loc) · 25.9 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 hello.world;

import com.mollie.mollie.Client;
import com.mollie.mollie.models.components.Security;
import com.mollie.mollie.models.components.WebhookEventTypes;
import com.mollie.mollie.models.errors.ErrorResponse;
import com.mollie.mollie.models.operations.*;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws ErrorResponse, Exception {

        Client sdk = Client.builder()
                .security(Security.builder()
                    .organizationAccessToken(System.getenv().getOrDefault("ORGANIZATION_ACCESS_TOKEN", ""))
                    .build())
            .build();

        CreateWebhookResponse res = sdk.webhooks().create()
                .idempotencyKey("123e4567-e89b-12d3-a456-426")
                .requestBody(CreateWebhookRequestBody.builder()
                    .name("Webhook #1")
                    .url("https://mollie.com/")
                    .eventTypes(EventTypes.of(WebhookEventTypes.PAYMENT_LINK_PAID))
                    .testmode(false)
                    .build())
                .call();

        if (res.createWebhook().isPresent()) {
            System.out.println(res.createWebhook().get());
        }
    }
}

Parameters

Parameter Type Required Description Example
idempotencyKey Optional<String> A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
requestBody Optional<CreateWebhookRequestBody> N/A

Response

CreateWebhookResponse

Errors

Error Type Status Code Content Type
models/errors/ErrorResponse 422 application/hal+json
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

package hello.world;

import com.mollie.mollie.Client;
import com.mollie.mollie.models.components.*;
import com.mollie.mollie.models.errors.ErrorResponse;
import com.mollie.mollie.models.operations.ListWebhooksRequest;
import com.mollie.mollie.models.operations.ListWebhooksResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws ErrorResponse, Exception {

        Client sdk = Client.builder()
                .testmode(false)
                .security(Security.builder()
                    .organizationAccessToken(System.getenv().getOrDefault("ORGANIZATION_ACCESS_TOKEN", ""))
                    .build())
            .build();

        ListWebhooksRequest req = ListWebhooksRequest.builder()
                .from("hook_B2EyhTH5N4KWUnoYPcgiH")
                .limit(50L)
                .sort(Sorting.DESC)
                .eventTypes(WebhookEventTypes.PAYMENT_LINK_PAID)
                .idempotencyKey("123e4567-e89b-12d3-a456-426")
                .build();


        sdk.webhooks().list()
                .callAsStream()
                .forEach((ListWebhooksResponse item) -> {
                   // handle page
                });

    }
}

Parameters

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

Response

ListWebhooksResponse

Errors

Error Type Status Code Content Type
models/errors/ErrorResponse 400 application/hal+json
models/errors/APIException 4XX, 5XX */*

update

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

Example Usage

package hello.world;

import com.mollie.mollie.Client;
import com.mollie.mollie.models.components.Security;
import com.mollie.mollie.models.components.WebhookEventTypes;
import com.mollie.mollie.models.errors.ErrorResponse;
import com.mollie.mollie.models.operations.*;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws ErrorResponse, Exception {

        Client sdk = Client.builder()
                .security(Security.builder()
                    .organizationAccessToken(System.getenv().getOrDefault("ORGANIZATION_ACCESS_TOKEN", ""))
                    .build())
            .build();

        UpdateWebhookResponse res = sdk.webhooks().update()
                .webhookId("hook_1234567890")
                .idempotencyKey("123e4567-e89b-12d3-a456-426")
                .requestBody(UpdateWebhookRequestBody.builder()
                    .name("Webhook #1")
                    .url("https://mollie.com/")
                    .eventTypes(UpdateWebhookEventTypes.of(WebhookEventTypes.PAYMENT_LINK_PAID))
                    .testmode(false)
                    .build())
                .call();

        if (res.entityWebhook().isPresent()) {
            System.out.println(res.entityWebhook().get());
        }
    }
}

Parameters

Parameter Type Required Description Example
webhookId String ✔️ Provide the ID of the related webhook. hook_1234567890
idempotencyKey Optional<String> A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
requestBody Optional<UpdateWebhookRequestBody> N/A

Response

UpdateWebhookResponse

Errors

Error Type Status Code Content Type
models/errors/ErrorResponse 404, 422 application/hal+json
models/errors/APIException 4XX, 5XX */*

get

Retrieve a single webhook object by its ID.

Example Usage: get-webhook-200

package hello.world;

import com.mollie.mollie.Client;
import com.mollie.mollie.models.components.Security;
import com.mollie.mollie.models.errors.ErrorResponse;
import com.mollie.mollie.models.operations.GetWebhookResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws ErrorResponse, Exception {

        Client sdk = Client.builder()
                .testmode(false)
                .security(Security.builder()
                    .organizationAccessToken(System.getenv().getOrDefault("ORGANIZATION_ACCESS_TOKEN", ""))
                    .build())
            .build();

        GetWebhookResponse res = sdk.webhooks().get()
                .webhookId("hook_1234567890")
                .idempotencyKey("123e4567-e89b-12d3-a456-426")
                .call();

        if (res.entityWebhook().isPresent()) {
            System.out.println(res.entityWebhook().get());
        }
    }
}

Example Usage: get-webhook-200-1

package hello.world;

import com.mollie.mollie.Client;
import com.mollie.mollie.models.components.Security;
import com.mollie.mollie.models.errors.ErrorResponse;
import com.mollie.mollie.models.operations.GetWebhookResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws ErrorResponse, Exception {

        Client sdk = Client.builder()
                .testmode(false)
                .security(Security.builder()
                    .organizationAccessToken(System.getenv().getOrDefault("ORGANIZATION_ACCESS_TOKEN", ""))
                    .build())
            .build();

        GetWebhookResponse res = sdk.webhooks().get()
                .webhookId("hook_1234567890")
                .idempotencyKey("123e4567-e89b-12d3-a456-426")
                .call();

        if (res.entityWebhook().isPresent()) {
            System.out.println(res.entityWebhook().get());
        }
    }
}

Parameters

Parameter Type Required Description Example
webhookId String ✔️ Provide the ID of the related webhook. hook_1234567890
testmode Optional<Boolean> 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 Optional<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
models/errors/ErrorResponse 404, 422 application/hal+json
models/errors/APIException 4XX, 5XX */*

delete

Delete a single webhook object by its webhook ID.

Example Usage

package hello.world;

import com.mollie.mollie.Client;
import com.mollie.mollie.models.components.Security;
import com.mollie.mollie.models.errors.ErrorResponse;
import com.mollie.mollie.models.operations.DeleteWebhookRequestBody;
import com.mollie.mollie.models.operations.DeleteWebhookResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws ErrorResponse, Exception {

        Client sdk = Client.builder()
                .security(Security.builder()
                    .organizationAccessToken(System.getenv().getOrDefault("ORGANIZATION_ACCESS_TOKEN", ""))
                    .build())
            .build();

        DeleteWebhookResponse res = sdk.webhooks().delete()
                .webhookId("hook_1234567890")
                .idempotencyKey("123e4567-e89b-12d3-a456-426")
                .requestBody(DeleteWebhookRequestBody.builder()
                    .testmode(false)
                    .build())
                .call();

        // handle response
    }
}

Parameters

Parameter Type Required Description Example
webhookId String ✔️ Provide the ID of the related webhook. hook_1234567890
idempotencyKey Optional<String> A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
requestBody Optional<DeleteWebhookRequestBody> N/A

Response

DeleteWebhookResponse

Errors

Error Type Status Code Content Type
models/errors/ErrorResponse 404, 422 application/hal+json
models/errors/APIException 4XX, 5XX */*

test

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

Example Usage

package hello.world;

import com.mollie.mollie.Client;
import com.mollie.mollie.models.components.Security;
import com.mollie.mollie.models.errors.ErrorResponse;
import com.mollie.mollie.models.operations.TestWebhookRequestBody;
import com.mollie.mollie.models.operations.TestWebhookResponse;
import java.lang.Exception;

public class Application {

    public static void main(String[] args) throws ErrorResponse, Exception {

        Client sdk = Client.builder()
                .security(Security.builder()
                    .organizationAccessToken(System.getenv().getOrDefault("ORGANIZATION_ACCESS_TOKEN", ""))
                    .build())
            .build();

        TestWebhookResponse res = sdk.webhooks().test()
                .webhookId("hook_1234567890")
                .idempotencyKey("123e4567-e89b-12d3-a456-426")
                .requestBody(TestWebhookRequestBody.builder()
                    .testmode(false)
                    .build())
                .call();

        // handle response
    }
}

Parameters

Parameter Type Required Description Example
webhookId String ✔️ Provide the ID of the related webhook. hook_1234567890
idempotencyKey Optional<String> A unique key to ensure idempotent requests. This key should be a UUID v4 string. 123e4567-e89b-12d3-a456-426
requestBody Optional<TestWebhookRequestBody> N/A

Response

TestWebhookResponse

Errors

Error Type Status Code Content Type
models/errors/ErrorResponse 404, 422 application/hal+json
models/errors/APIException 4XX, 5XX */*