Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. JSON NXSL

JSON NXSL

Scheduled Pinned Locked Moved Support
9 Posts 3 Posters 34.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    M
    MarcusH
    wrote on last edited by
    #1

    Hi,

    Working on integration NetXMS with GLPI using RestAPI and web service definitions. Everything is working except i can not get a handle arround the JSON response.

    Is there no support for JSON arrays in NXSL functions?

    For example i have this response and i want to loop these values and count total

    [
       {
          "id": 178
       },
       {
          "id": 179
       },
       {
          "id": 181
       }
    ]
    
    1 Reply Last reply
    0
    • M
      M
      MarcusH
      wrote on last edited by
      #2

      Almost always when you post a question you find an answer shortly after. I Solved my counting issue by using ->replace("[", "")->replace("]", "")->split(",")
      With that i get an array with a JSON in each that i can loop through.

      1 Reply Last reply
      0
      • F
        F
        Filipp Sudanov
        wrote on last edited by
        #3

        Yes, there is json support in nxsl, there is JsonParse() which would produce JsonObject or JsonArray. Support for jsons which have array at the root level (which is the case in your example) was added just recently, it will be available in next patch release. So after that release is out you could do something like this:

        s = """[
           {
              "id": 178
           },
           {
              "id": 179
           },
           {
              "id": 181
           }
        ]""";
        
        p = JsonParse(s);
        println(classof(p));
        count = 0;
        for (v: p->values) {
          println(classof(v));
          count = count + v->get("id");
        }
        println(count);
        

        which would produce the following:

        Result:
        
        JsonArray
        JsonObject
        JsonObject
        JsonObject
        538
        
        
        *** FINISHED ***
        
        1 Reply Last reply
        0
        • M
          M
          MarcusH
          wrote on last edited by
          #4

          Wonderful, looking forward to the release.

          On a sidenote is support for Bearer authentication with token planned for implementation soon on webservice?

          1 Reply Last reply
          0
          • F
            F
            Filipp Sudanov
            wrote on last edited by
            #5

            Try putting the token into password field for Bearer authentication. Pls give us an update, if this works.

            1 Reply Last reply
            0
            • M
              M
              MarcusH
              wrote on last edited by
              #6

              If use Bearer auth i get "OAuth 2.0 Bearer Access Token not implemented" in web service errorMessage.

              For info running 4.1.420 on both server and agent

              1 Reply Last reply
              0
              • V
                V
                Victor Kirhenshtein
                wrote on last edited by
                #7

                This message indicates that agent was built with libcurl without bearer authentication support. On what platform you run agent and how did you install it?

                1 Reply Last reply
                0
                • M
                  M
                  MarcusH
                  wrote on last edited by
                  #8

                  Agent is running on Windows, installed with official package

                  1 Reply Last reply
                  0
                  • F
                    F
                    Filipp Sudanov
                    wrote on last edited by
                    #9

                    Looks like it's missing in Windows builds. I've created an issue for this, so one day developers will have a look.

                    Meanwhile you can put netxms agent on any linux machine and configure it as a proxy - token support should be working on Linux.

                    1 Reply Last reply
                    0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    Powered by NodeBB Contributors
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups