Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Using POST for a NRQL query

feature-request
nrql
http_errors

#1

I was building a really big query. I got 414 http error.

Is it possible to do a SELECT via

curl -H "Accept: application/json" -H "X-Query-Key: YOUR_KEY_HERE" "https://insights-api.newrelic.com/v1/accounts/648105/query?nrql=SELECT%20average%28duration%29%20FROM%20PageView"

to send the nrql as POST instead of GET?


#2

Hi @Brian_Telus: POST is used to update data, GET to retrieve data when used via REST calls.

A 414 error specifies that the request is too long but your request looks fine and I have just run a longer query, more attributes, which has executed with no errors.


#3

@stefan_garnham,

Oh believe me the request I am making is super big. Thats why I want to use a POST :smiley:


#4

If the query you are making is very long, or the data set that you are requesting is very big, then you may be hitting some limits within the API. Have you looked into the documentation to see if you are hitting any defined limits?

Otherwise, I suggest raising a support ticket.


#5

@stefan_garnham

The query is really long because I’m trying to query page URLs that are a pattern; so I have to build long queries rather than a regular expression so you can imagine how big that could get :slight_smile:

I am hitting 414 limits; my queries are over 8,500 characters long (encoded)


#6

Could you not perform multiple queries, one for each pattern, and merge the results?


#7

Could you maybe give us an example of a couple of patterns? There is an ability to use LIKE in NRQL, but without an example I’m unsure if that would meet your needs.


#8

@alexis

Hey sorry I’ve already moved onto another approach. But basically I was trying to mimic regular expression it looked kinda like

WHERE (pageUrl LIKE '%://domain.com/%' OR pageUrl LIKE '%://www.domain.com/%') 
AND (pageURL LIKE '%/en/desired_uri/%/other_uri/%' OR pageURL LIKE '%/fr/desired_uri/%/other_uri/%')

And so on and so on for other languages & regions


6/17/2016 Post of the Week! Insights, Synthetics, Linux and Feature Requests!
#9

Hey @Brian_Telus - if you’re happy with your new approach, then no worries. I’m thinking maybe there are some ways to get this to work in Insights, perhaps using a series of queries that vary pageUrl or browserTransactionName, but it may be a bit complex. Let us know if you want to explore further or not.


#10

@alexis

I think I just want to add to the feature request to be able to query by regular expression or to allow queries to be sent via POST.

I have a good idea how to get around this issue but I think others would appreciate this sort of feature.


#11

Hi all, I wanted to chime in and let you know that we do now support passing longer NRQL to queries via POST. The trick is to use the application/x-www-form-urlencoded content type and pass your url-escaped query as the value of the nrql param.

For example. using curl…

curl -X POST -H “Accept: application/json” -H “X-Query-Key: YOU_QUERY_API_KEY” -d “nrql=SELECT+count%28*%29+FROM+Transaction” “https://insights-api.newrelic.com/v1/accounts/YOUR_ACCOUNT_ID/query

Hope that helps future visitors.


#12

Hi,
i’ve just tried to use the POST example you provided and I get this error message:

{“error”:“NRQL Syntax Error: Error at line 1 position 7, unexpected ‘+’”}


#13

@alex.rojo It looks like Jonathan’s code sample is incorrect.

I got the following to work (basically do NOT url encode):
curl -X POST -H “Accept: application/json” -H “X-Query-Key: YOU_QUERY_API_KEY” -d “nrql=SELECT count (*) FROM Transaction” “https://insights-api.newrelic.com/v1/accounts/YOUR_ACCOUNT_ID/query”


#14

For what it’s worth the API key page in the account will format the CURL command for you using string nrql.