Getting 404 status when trying to connect through API


I am trying to connect New Relic to query the logs for Automation Tests using Selenium Java(Rest Assured), When i hit the new relic end point using Postman i am able to get the response but when i tried the same using my Selenium Java code i am getting the 404 not found status, See below details:

I am using all the following information but getting 404, please help me to resolve this issue.

Uri[YOUR_ACCOUNT_ID]/query?nrql=YOUR_URL_ENCODED_QUERY -Headers @{“X-Query-Key”=“YOUR_QUERY_KEY”} -ContentType “application/json” -Method GET


Hi, @nakula: Have you replaced the placeholder [YOUR_ACCOUNT_ID] with your actual account ID? You will also need to replace the other placeholders, YOUR_URL_ENCODED_QUERY and YOUR_QUERY_KEY.

Yes I did, I was just telling you that i didn’t miss anything and i was able to hit this request from Postman and got the response.


Can you post your Java code that is not working?

Hi Thanks a lot for your quick responses, see below code: i have replaced the original keys and other data. fyi.
String baseUri = “”;
//encoded url
String url = “XXXXXXXX”

RestAssured.baseURI = baseUri;
Response response = RestAssured.given()
.header(“Content-Type”, “application/json”)

It looks like you are only passing the encoded query in the .get(), not the baseUri? It should be baseUri + url.

Thanks a lot for your quick replies @philweber, I did try baseUri+url and it said 400 bad request. appreciate your help.

Here is an example that works. Replace account ID and query API key with your own:

String baseUri = "";
String nrqlQuery = "SELECT * FROM PageView";
String url = baseUri + "?nrql=" + nrqlQuery;

Response response = RestAssured
    .header("X-Query-Key", "XXXXXXXXXXXXXX")
    .header("Content-Type", "application/json")

1 Like

I got the response now, thanks so much for your help, the problem was with encoded query, when i used the query directly without encoding it worked and i wonder why they mentioned to use the encoded query? and interestingly it(encoded query) worked with postman, as you mentioned working example, it triggered me to use the query without encoding.
Thanks again so much for your help @philweber.


1 Like

I assume that RestAssured automatically encodes the query string. Glad you got it working!

1 Like