Graylog Rest API Request Post - Fehler Code 405

Hello, everyone,
I have a problem with my python script. When I run the script, I always get an error message or the status code 405. When I type the following at “http://127.0.0.1:9000/api/api-browser/#!/Search/Messages/retrieveForSearch_post_2” and test my request, I get plausible results returned. Why don’t I get these results when I run the program from the terminal?
Maybe someone had a similar problem before and can help me. I would be very grateful!

type or paste code here

#!/usr/bin/env python3
import argparse
import requests
import sys
from requests.auth import HTTPBasicAuth

def main():


  header = {
    'X-Requested-By':'Icinga',
  }

  request = {"chunk_size": 10, "timerange": {"type": "relative","range": 1000},"limit": 10, "query_string": {"query_string": "agent_name:XX-XX-XX","type": "elasticsearch"}}

  response = requests.post("https://xxxxx.test/api/views/messages", json=request, auth=HTTPBasicAuth("test", "t1e2s3t"), headers=header, timeout=10)



  print("Status Code ")
  print(response.status_code)
  print(response.reason)


#test
  if response.status_code == 200:
    print("ok")
    if args.time_range < 600:
      str_timerange = "{} s".format(args.time_range)
    elif args.time_range < 14400:
      str_timerange = "{:.0f} m".format(args.time_range/60)
    else:
      str_timerange = "{} h".format(args.time_range/3600)

    # if data['total_events'] >= args.crit:
      # print("CRITICAL - {} alerts in the last {} | alerts={}".format(data['total_events'], str_timerange, data['total_events']))
      # return 2

  else:
    print("UNKNOWN - HTTP Status Code: {}".format(response.status_code))
    return 3

if __name__ == "__main__":
  ret=main()
  sys.exit(ret)

Hello @S1994

First, I have not used Python script with Graylog. But I was looking at your API posted and matching with the error. Not sure if that is the right API call. The reason I stated this was I looked here

System/Nodes → API Browser

Unable to find this API or I have over looked it.

And

https://xxxxx.test/api/views/messages"

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.