Question regarding RESTFUL

Hi everbody,
we use a DMS system (ecoDMS) with an API. I want to extract some information from it.
Manually (with curl) I can connect with the api.
The results is an json array like

[{"docId":11388,"clDocId":11402,"archiveName":"1","classifyAttributes":{"dyn_2_1580936356174":"prüfen und freigeben","docart":"5","docid":"11388#11402","defdate":"","changeid":"x.x","dyn_1_1580936356174":"ER548","dyn_0_1580936356172":"2023","revision":"1.0","rechte":"W","folder":"1","cdate":"2023-07-04","bemerkung":"per Lastschrifteinzug","ctimestamp":"2023-07-12 12:09:25","mainfolder":"","status":"1"},"editRoles":["r_x","r_LDAP_5000-rg","r_LDAP_100-rg","r_LDAP_100-buero"],"readRoles":[]},{"docId":11387,"clDocId":11401,"archiveName":"1","classifyAttributes":{"dyn_2_1580936356174":"prüfen und freigeben","docart":"5","docid":"11387#11401","defdate":"","changeid":"x.x","dyn_1_1580936356174":"ER547","dyn_0_1580936356172":"2023","revision":"1.0","rechte":"W","folder":"1","cdate":"2023-07-12","bemerkung":" überweisen","ctimestamp":"2023-07-12 12:07:21","mainfolder":"","status":"1"},"editRoles":["r_x_x","r_LDAP_4000-rg","r_LDAP_100-rg","r_LDAP_100-buero"],"readRoles":[]}]

I want to create a sensor which gives back all 'dyn_0_ … ’ concatenated. I tried a lot of things, but I’m not succesful up ti now.
As a Query, I would take ‘[*].classifyAttributes.dyn_1_1580936356174’, maybe that converted to a string with join().
This will not work with RESTFUL.

Can anybody help me?

You have two options imo

  1. if you can get to the API ouptut with e.g. curl then you could write a command_line sensor and concatenate the curl output using jq…does not need to be curl but the idea is top pipe the output through jq, this way you would have 1 new snsor with the concatenated values
  2. you can load above output as a whole into a sensor attributes and then run a template sensor on top to get to the concatenated values, here you would have 2 sensors then

btw, i you only have this output with two block containing fixed dyn_0_1580936356172 then it is much simpler…

value_template: "{{ value_json.0.classifyAttributes.dyn_0_1580936356172 + ' ' + value_json.1.classifyAttributes.dyn_0_1580936356172 }}"
value_template: "{{ value_json|map(attribute='classifyAttributes.dyn_0_1580936356172')|list }}"

will return a list. From the JSON you posted above, that will be ["2023","2023"].

You can play in the template editor to get what you want. Try pasting in this:

{% set value_json = [{"docId":11388,"clDocId":11402,"archiveName":"1","classifyAttributes":{"dyn_2_1580936356174":"prüfen und freigeben","docart":"5","docid":"11388#11402","defdate":"","changeid":"x.x","dyn_1_1580936356174":"ER548","dyn_0_1580936356172":"2023","revision":"1.0","rechte":"W","folder":"1","cdate":"2023-07-04","bemerkung":"per Lastschrifteinzug","ctimestamp":"2023-07-12 12:09:25","mainfolder":"","status":"1"},"editRoles":["r_x","r_LDAP_5000-rg","r_LDAP_100-rg","r_LDAP_100-buero"],"readRoles":[]},{"docId":11387,"clDocId":11401,"archiveName":"1","classifyAttributes":{"dyn_2_1580936356174":"prüfen und freigeben","docart":"5","docid":"11387#11401","defdate":"","changeid":"x.x","dyn_1_1580936356174":"ER547","dyn_0_1580936356172":"2023","revision":"1.0","rechte":"W","folder":"1","cdate":"2023-07-12","bemerkung":" überweisen","ctimestamp":"2023-07-12 12:07:21","mainfolder":"","status":"1"},"editRoles":["r_x_x","r_LDAP_4000-rg","r_LDAP_100-rg","r_LDAP_100-buero"],"readRoles":[]}] %}

{{ value_json|map(attribute="classifyAttributes.dyn_0_1580936356172")|list }}

If you explain exactly what you want the output to look like, we can probably help further.

Interesting, and what if the dyn_0 is not unique in its key apart from the dyn_0_ part?

Thanks a lot for the prompt replies from all!

gives the right list. Is it possible to get it not as list bus as string, all entities concatenated? I just need a string with all entitiets, ideally separated by “,”.

Add |join(',') after the list.

1 Like

Thanks a lot!