NetXMS Support Forum

English Support => General Support => Topic started by: MarcusH on August 26, 2022, 04:16:54 PM

Title: JSON NXSL
Post by: MarcusH on August 26, 2022, 04:16:54 PM
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
   }
]
Title: Re: JSON NXSL
Post by: MarcusH on August 26, 2022, 04:42:52 PM
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.
Title: Re: JSON NXSL
Post by: Filipp Sudanov on August 30, 2022, 04:57:50 PM
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 ***
Title: Re: JSON NXSL
Post by: MarcusH on August 31, 2022, 12:09:31 PM
Wonderful, looking forward to the release.

On a sidenote is support for Bearer authentication with token planned for implementation soon on webservice?
Title: Re: JSON NXSL
Post by: Filipp Sudanov on September 02, 2022, 05:16:59 PM
Try putting the token into password field for Bearer authentication. Pls give us an update, if this works.
Title: Re: JSON NXSL
Post by: MarcusH on September 05, 2022, 02:41:31 PM
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
Title: Re: JSON NXSL
Post by: Victor Kirhenshtein on September 06, 2022, 12:54:23 PM
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?
Title: Re: JSON NXSL
Post by: MarcusH on September 12, 2022, 03:08:25 PM
Agent is running on Windows, installed with official package
Title: Re: JSON NXSL
Post by: Filipp Sudanov on September 16, 2022, 03:36:44 PM
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.