Get JSON request body

I want to know if there is any other way to store httpbody in variable since getHttpBody() is deprecated after 5.5. in my case, i want to get the request body in json string for later use in authentication things, any suggest ? cant find the related one at latest api doc, thanks before

What do you mean by this?
Please point me to the URL where you read it.


short story is, i want to get the API request body as json string and store it in some variable before hitting the API request, now i can use getHttpBody() which is return json request body as string, but the IDE says its deprecated, is there any new solution related for my case ? thanks

API doc is here:

Hmmm seems like not related with my case, i just want to get the request body not setting the body content, anyway thanks with the answer, i think i will stick with the Deprecated method one

I think you were confused by a mistake in the doc:

Please use setBodyContent(HttpBodyContent) instead.

This sentence must be a mistake.

You would want to look at RequestObject::getBodyContent

I think that the API doc requires a correction.

1 Like

LOL you’re right, thanks for the solution, now it works like a charm, just had to put it at HttpTextBodyContent since it implemented Interfaces and Traits of HttpBodyContent

The solution become like this, in case someone had the same problem with me, this is my solution

anyway thanks again for the help @kazurayam :grin:

i got the same constraint as you, i want to get request body in json string to use later in authentication. but the output that comes out is the body of the response, not the body of the request

What the error message said? Please share the log to us.

oh sorry there is no error, but the output that appears is the body response, not the body request as I wanted

Of course, the output will be the body of the response because your code tells to get body content of the variable named response.
スクリーンショット 2022-10-13 13.53.36

Do you want to look at the request?
Then should write your code to do that.

then how can I get the request body from the object repository that I will hit?


You haven’t explained your problem enough.

Please follow the following guidance.

You had better create a new post on your own and provide enough information to us.