Loop into json

Hi,

Sorry, I guess it’s a noob question, but I can’t get away with this situation.

I use an opensource CRM called Dolibarr and I try to get information about a calendar event through its API. Getting a response is not a problem at all. It looks like this:

[
  {
    "table_rowid": "id",
    "id": "11819",
    "ref": "11819",
    "type_id": "163061",
    "type_code": "ACC_MONT",
    "type": "Accompagnement >>> Montage de projet",
    "type_color": null,
    "code": "ACC_MONT",
    "label": "Projet tabac vapottage Mines St-Étienne",
    "datec": 1633093318,
    "datem": 1633093318,
    "authorid": "2",
    "usermodid": null,
    "datep": 1632988800,
    "datef": "",
    "durationp": -1,
    "fulldayevent": "0",
    "punctual": "1",
    "percentage": "-1",
    "location": "",
    "transparency": "1",
    "priority": "0",
    "userassigned": {
      "2": {
        "id": "2",
        "mandatory": "0",
        "answer_status": "0",
        "transparency": "1"
      }
    },
    "userownerid": "2",
    "userdoneid": null,
    "socpeopleassigned": {
      "16061": {
        "id": "16061",
        "mandatory": "0",
        "answer_status": "0",
        "transparency": "0"
      },
      "17034": {
        "id": "17034",
        "mandatory": "0",
        "answer_status": "0",
        "transparency": "0"
      },
      "17483": {
        "id": "17483",
        "mandatory": "0",
        "answer_status": "0",
        "transparency": "0"
      },
      "18057": {
        "id": "18057",
        "mandatory": "0",
        "answer_status": "0",
        "transparency": "0"
      }
    },
    "otherassigned": [],
    "usertodo": null,
    "userdone": null,
    "socid": "449",
    "contactid": "17034",
    "elementid": null,
    "elementtype": null,
    "icalname": null,
    "icalcolor": null,
    "actions": [],
    "email_msgid": null,
    "email_from": null,
    "email_sender": null,
    "email_to": null,
    "email_tocc": null,
    "email_tobcc": null,
    "email_subject": null,
    "errors_to": null,
    "import_key": null,
    "array_options": [],
    "linkedObjectsIds": [],
    "fk_project": null,
    "state": null,
    "state_id": null,
    "state_code": null,
    "region": null,
    "region_code": null,
    "modelpdf": null,
    "note_public": null,
    "note_private": null,
    "note": "a note",
    "lines": null,
    "type_picto": null,
    "type_short": ""
  }
]

In socpeopleassigned are listed all people linked to the event. I want to get these contacts informations by looping in socpeopleassigned and executing an API request for each contact. But I dont’ really know how to do this.

My final goal is to get all informations about the event in order to generate a reporting file.

Hope I’m understandable :smile:

Thanks a lot!

Assuming that you have only user IDs and need to make an API call to get the full user info, I’d suggest making a list of users in a separate node and use it as a source for HTTP Request (or whatever Node you use to retrieve data from Dolibarr).

How to make this list:

  1. In your example the problematic part is the socpeopleassigned can have random item names.
    So, using jmespath object projection capabilities we can first extract user IDs and then use Item Split node to make an array of IDs.
  2. Alternatively, you can use Object.keys() function to extract socpeopleassigned element names. It will also work because the element names are the same as user id.

Here’s the complete example

2 Likes

Thank you very much for your explanation :+1: It works as expected :slight_smile:

1 Like

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