diff --git a/CHANGELOG.md b/CHANGELOG.md index 57e5a58..6eb002c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Add support for JSON API calls with new method `callApiJson`. ## [1.15.0] - 2025-01-20 ### Added @@ -233,4 +235,4 @@ of the alert (zaproxy/zaproxy#1341), older methods were deprecated. [1.2.0]: https://github.com/zaproxy/zap-api-java/compare/v1.1.1...v1.2.0 [1.1.1]: https://github.com/zaproxy/zap-api-java/compare/v1.1.0...v1.1.1 [1.1.0]: https://github.com/zaproxy/zap-api-java/compare/v1.0.0...v1.1.0 -[1.0.0]: https://github.com/zaproxy/zap-api-java/compare/6c778f77a817e1ff71e9279e4759535d482e8393...v1.0.0 \ No newline at end of file +[1.0.0]: https://github.com/zaproxy/zap-api-java/compare/6c778f77a817e1ff71e9279e4759535d482e8393...v1.0.0 diff --git a/subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/core/ClientApi.java b/subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/core/ClientApi.java index 191f1a1..7f27a9a 100644 --- a/subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/core/ClientApi.java +++ b/subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/core/ClientApi.java @@ -472,9 +472,27 @@ public byte[] callApiOther( String method, Map params) throws ClientApiException { + return getBytes(requestMethod, "other", component, type, method, params); + } + + public String callApiJson( + String component, String type, String method, Map params) + throws ClientApiException { + byte[] json = getBytes(HttpRequest.GET_METHOD, "JSON", component, type, method, params); + return new String(json, StandardCharsets.UTF_8); + } + + private byte[] getBytes( + String requestMethod, + String format, + String component, + String type, + String method, + Map params) + throws ClientApiException { try { HttpRequest request = - buildZapRequest(requestMethod, "other", component, type, method, params); + buildZapRequest(requestMethod, format, component, type, method, params); if (debug) { debugStream.println("Open URL: " + request.getRequestUri()); }