A java client for the PagerDuty APIs.
implementation("io.github.primelib:pagerduty4j-rest:<latestVersion>")
Click to view instructions for other build tools.
Consumer Specification Approach
PagerDutyRESTConsumerApi client = PagerDutyRESTFactory.create(spec -> {
spec.api(PagerDutyRESTConsumerApi.class);
spec.baseUrl("https://api.pagerduty.com");
spec.apiKeyAuth(authSpec -> authSpec.apiKey("<token>"));
// optional: http proxy
spec.httpProxy(proxySpec -> {
proxySpec.host("localhost");
proxySpec.port(8080);
});
});
client.listIncidentAlerts(spec -> {
spec.id("15");
spec.limit(100);
});
Parameter Approach
PagerDutyRESTApi client = PagerDutyRESTFactory.create(spec -> {
spec.api(PagerDutyRESTApi.class);
spec.baseUrl("https://api.pagerduty.com");
spec.apiKeyAuth(authSpec -> authSpec.apiKey("<token>"));
// optional: http proxy
spec.httpProxy(proxySpec -> {
proxySpec.host("localhost");
proxySpec.port(8080);
});
});
client.listIncidentAlerts("15", 100, null, null, null, null, null, null);
NOTE: The Parameter Approach
can break if the API changes. The Consumer Specification Approach
is more resilient to API changes.
implementation("io.github.primelib:pagerduty4j-events-v2:<latestVersion>")
Click to view instructions for other build tools.
Consumer Specification Approach
PagerDutyEventsV2ConsumerApi client = PagerDutyEventsV2Factory.create(spec -> {
spec.api(PagerDutyEventsV2ConsumerApi.class);
spec.baseUrl("https://events.pagerduty.com/v2");
// optional: http proxy
spec.httpProxy(proxySpec -> {
proxySpec.host("localhost");
proxySpec.port(8080);
});
});
client.createChangeEvent(spec -> {
spec.createChangeEventRequest(CreateChangeEventRequest.of(requestSpec -> {
requestSpec.routingKey("<routingKey>");
requestSpec.payload(ChangeEventPayload.of(payloadSpec -> {
payloadSpec.summary("<summary>");
payloadSpec.source("<source>");
}));
}));
});
Parameter Approach
PagerDutyEventsV2Api client = PagerDutyEventsV2Factory.create(spec -> {
spec.api(PagerDutyEventsV2Api.class);
spec.baseUrl("https://events.pagerduty.com/v2");
// optional: http proxy
spec.httpProxy(proxySpec -> {
proxySpec.host("localhost");
proxySpec.port(8080);
});
});
client.createChangeEvent(new CreateChangeEventRequest(new ChangeEventPayload("<summary>", null, "<source>", null), "<routingKey>", null, null));
NOTE: The Parameter Approach
can break if the API changes. The Consumer Specification Approach
is more resilient to API changes.
Released under the MIT License.