Skip to content

Add method to get JSON responses #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 31, 2025
Merged

Add method to get JSON responses #129

merged 5 commits into from
Jan 31, 2025

Conversation

blue42-david
Copy link
Contributor

@blue42-david blue42-david commented Jan 21, 2025

Add support for JSON API calls with new method callApiJson.

Background:
There are some API methods (e.g. alert/view/alertCountsByRisk) which only work with JSON as the requested response format. Not using JSON (this is a different bug) will result in an "Internal Error" (e.g. Alert#alertCountsByRisk(String, String)).
The new method callApiJson allows java client API users to request a JSON response. We now also can create/build JSON models (e.g. with/for GSON) further enhancing the APIs usability.

@psiinon
Copy link
Member

psiinon commented Jan 21, 2025

Logo
Checkmarx One – Scan Summary & Details56491e39-67cd-4494-9139-f9cd687cbeae

Great job, no security vulnerabilities found in this Pull Request

@psiinon
Copy link
Member

psiinon commented Jan 21, 2025

@daivdwe can you tell us which API end points dont work if JSON is selected? And more details on how to reproduce the problems if they dont happen in all cases.
Those would be bugs that we should fix.

@kingthorin
Copy link
Member

alert/view/alertCountsByRisk works as HTML but does bomb as XML.

(Note it's actually String, Boolean not String, String)

@psiinon
Copy link
Member

psiinon commented Jan 21, 2025

Raise an issue? Could be a goodfirstissue ?

@blue42-david
Copy link
Contributor Author

Hi @psiinon,

yes - @kingthorin described it correctly.

I would still love to have my changes as a feature in an upcoming release as it is currently not possible to call the JSON API with the Java Client API.

@blue42-david
Copy link
Contributor Author

Hi @kingthorin,

no it is String, String:

  public ApiResponse alertCountsByRisk(String url, String recurse) throws ClientApiException {

@kingthorin
Copy link
Member

Sorry I was thinking of what the web API expects or tries to parse.

@blue42-david
Copy link
Contributor Author

I added the DCO flagged missing sign off.

@thc202
Copy link
Member

thc202 commented Jan 23, 2025

The changelog should be updated.

@thc202 thc202 changed the title Added callApiJSON Add method to get JSON responses Jan 23, 2025
Add support for JSON API calls with new method callApiJSON.

Backgound:
There are some API methods (e.g. alert/view/alertCountsByRisk) which only work with JSON as the requested response format. Not using JSON (this is a different bug) will result in an "Internal Error" (e.g. Alert#alertCountsByRisk(String, String)).
The new method callApiJSON allows java client API users to request a JSON response. We now also can create/build JSON models (e.g. with/for GSON) further enhancing the APIs usability.

Signed-off-by: daivdwe <[email protected]>
Improved usability of new callApiJSON method by defaulting to HttpRequest.GET_METHOD

Signed-off-by: daivdwe <[email protected]>
Changed name from callApiJSON to callApiJson and return type from byte[] to String.

Signed-off-by: daivdwe <[email protected]>
@blue42-david
Copy link
Contributor Author

Hi @thc202, I changed the name from callApiJSON to callApiJson and return type from byte[] to String.

@blue42-david
Copy link
Contributor Author

blue42-david commented Jan 31, 2025

Hi together, when can i roughly expect to find my changes in a release?

@thc202
Copy link
Member

thc202 commented Jan 31, 2025

There's still this pending #129 (comment)

Unreleased: Add support for JSON API calls with new method callApiJson

Signed-off-by: daivdwe <[email protected]>
@blue42-david
Copy link
Contributor Author

Hi @thc202, sorry - I missed that this was an assignment for me.
The CHANGELOG.md is updated now.

Signed-off-by: thc202 <[email protected]>
@thc202 thc202 enabled auto-merge (squash) January 31, 2025 19:24
@thc202
Copy link
Member

thc202 commented Jan 31, 2025

Thank you!

@thc202 thc202 merged commit 3ad04c0 into zaproxy:main Jan 31, 2025
6 checks passed
@thc202
Copy link
Member

thc202 commented Feb 3, 2025

This is released in version 1.16.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants