Ad Widget

Collapse

API Call through item with bearer token

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jvdb
    Junior Member
    • Feb 2022
    • 23

    #1

    API Call through item with bearer token

    hi,

    I want to create an item that does an api call with a bearer token.
    I got it working with a regular apiToken but with the bearer token I can't seem to get it to work.
    I have set it up as follows:
    Click image for larger version

Name:	image.png
Views:	455
Size:	26.2 KB
ID:	497702

    The url is the API URL
    Query fields where bearer token should be

    is there something I can do to get it to work?
  • PZakrzewski
    Junior Member
    • Dec 2024
    • 12

    #2
    Hey!

    You’re currently sending the Bearer token in the Query fields, but it should be included in the Headers. Here’s how to fix it:

    1. In the HTTP Agent item configuration, add the following in the Headers section:
    Name: Authorization
    Value: Bearer {your_token}
    2. Remove the token from the Query fields (it’s not needed there).

    This should resolve the issue, as Bearer tokens are typically sent in the request headers, not query parameters. Let me know if you encounter further issues!

    Comment


    • xorms1289
      xorms1289 commented
      Editing a comment
      Thanks "My token changes periodically. What should I do in this case?
  • xorms1289
    Junior Member
    • Feb 2025
    • 1

    #3
    "My token changes periodically. What should I do in this case?

    Comment

    • Brambo
      Senior Member
      • Jul 2023
      • 245

      #4
      Originally posted by xorms1289
      "My token changes periodically. What should I do in this case?
      Place the token in a macro so you can easily update it on host level. Or do it in a fancy way where you have a zabbix script item (or any other script which can do that for you AND talk to zabbix api) which runs at a certain interval which request the new token, and then with the zabbix API update the macro on your host with the new token.

      Comment


      • xorms1289
        xorms1289 commented
        Editing a comment
        thank you!!!! I solved that!
    • PZakrzewski
      Junior Member
      • Dec 2024
      • 12

      #5
      i believe the easiest way is to actually write a script which would do that for You. especially if the change is frequent, if not then You can do that manually. i of course assume You're using macros, this is very convenient

      Comment


      • xorms1289
        xorms1289 commented
        Editing a comment
        thank you!!!! I solved that!
    Working...