amimas
(Aver)
January 17, 2018, 3:05am
1
I’m trying to use Groovy’s RESTClient to connect to Graylog server and use it’s REST API. I want a JSON response from Graylog.
This is my RESTClient (Graylog is running on my local machine)
def restClient = new RESTClient("http://localhost:9000/api/")
restClient.auth.basic 'admin', 'admin'
def response = restClient.get(
path:"search/universal/relative?query=hello&range=50000&fields=message&decorate=true",
headers:[
"Accept": "application/json"
]
)
It’s a simple rest client trying to search for a word “hello” in Graylog’s messages. I keep getting 404 Not Found exception
If I use the following curl command, I do get my JSON response.
curl --user admin:admin -H ‘Accept: application/json’ -X GET “http://localhost:9000/api/search/universal/relative?query=hello&range=50000&fields=message ”
I tried the same REST API call using Postman and am able to get a JSON response back.
What did I miss in my groovy rest client that is causing it to receive a HttpResponseException?
I noticed that If I change the “path” parameter to “streams”, everything works just fine. But, I can’t seem to call the search API successfully.
Graylog version is 2.2.3-1
jochen
(Jochen)
January 17, 2018, 8:23am
2
You might want to take another look at the URI you’re building.
I’m pretty sure that the part after the first question mark is not the URI path component.
The syntax of generic URIs and absolute URI references was first defined in Request for Comments (RFC) 2396, published in August 1998, and finalized in RFC 3986, published in January 2005. A generic URI is of the form: It comprises: 1.The scheme, consisting of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus (+), period (.), or hyphen (-). Although schemes are case-insensitive, the canonical form is lowercase and documents that specify sche...
amimas
(Aver)
January 17, 2018, 10:11pm
3
That it!! It was because of the querystring being included in the path. The rest client has separate parameter for that. Here’s how it should be. Thanks a lot.
def restClient = new RESTClient("http://localhost:9000/api/")
restClient.auth.basic 'admin', 'admin'
def response = restClient.get(
path:"search/universal/relative",
query: [
"query" : "hello",
"range" : 50000,
"fields" : "message"
],
headers:[
"Accept": "application/json"
]
)
system
(system)
Closed
January 31, 2018, 10:11pm
4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.