cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Send POST request to GraphQL API from Java Application

rbaida
New Contributor

Hello,

I have a problem with sending POST requests to GraphQL API from Java Application. For example, I want to get a list of applications filtered by name and I send a request with the next body:

String query = "{\"query\":\"{application(filter:{name_contains: \"test\"}){id name comment}}\"}";

 But all I get when trying to read the response is 

Object reference not set to an instance of an object.

When I'm using the GET method (to get data from my dataset), response is as expected, a JSON with a proper data.

Please, help me with this topic, maybe someone could provide a sample code sending POST request and reading the response?

1 Reply

rbaida
New Contributor

Well, that's the second time I've asked a question here and then I managed to find the answer within few minutes by myself!

The correct query looks like this:
String query = "{\"query\":\"query{ application(filter:{name_contains: \\\"test\\\"}){ id name comment }}\",\"variables\":{}}";

Gotta use the postman when creating next Java queries!