How can I send an array in a custom property?

Created on 14 March 2024, 8 months ago
Updated 29 March 2024, 8 months ago

Problem/Motivation

I'm using ECA together with the HTTP Client Manager module to consume an API when a node is created, that API requires that I send some strings and also an array as parameters, all of them in json format, so if I create an Http Config Request in the HTTP Client Manager UI, I need to send that array parameter like this: [ "foo", "bar", "test" ] and when is executed it works like a charm. My problem is when I create a model in BPMN.iO and I use that API command in an action I don't know how I can send an that array in the custom property of the action, I mean, I have tried to send it in different ways, but it's not working, this are some of the ways I have tried:

  • [ "foo", "bar", "test" ]
  • [ foo, bar, test ]
  • [ 'foo', 'bar', 'test' ]
  • \[ "foo", "bar", "test" \]
  • '[ "foo", "bar", "test" ]'
  • '\[ "foo", "bar", "test" \]'
  • "foo", "bar", "test"
  • foo, bar, test
  • - foo - bar - test

I have also tried creating a custom action that is executed previously to the API request action, the custom action stores that array in the Private temporary store, later with another action I read that value to store it in a token and finally I send that token to the action exposed by HTTP Client Manager, but it still doesn't work, in watchdog is logged an error like this:

Failed execution of Create discussion (Activity_0ogtuaz) from ECA New node (process_mjo7jgs) for event Drupal\eca_content\Event\ContentEntityInsert: Validation errors: [users] must be of type array.

The parameter I need to send as an array it's called "users" in my HTTP Client Manager command.

Is there any way I can send the array in a custom property?

💬 Support request
Status

Closed: works as designed

Version

9.3

Component

User interface

Created by

🇲🇽Mexico ovilla

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ovilla
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Failed execution of Create discussion (Activity_0ogtuaz) from ECA New node (process_mjo7jgs) for event Drupal\eca_content\Event\ContentEntityInsert: Validation errors: [users] must be of type array.

    What action plugin is actually giving you this error message?

    Can you provide the plugin configuration you used for that in your ECA model?

  • 🇲🇽Mexico ovilla

    Thanks for the answer jurgenhaas.

    It is an action plugin created by the HTTP Client Manager module, with that action I'm trying to request an API of rocket.chat to create a room, and among other things I want to send a list of users to join that room, but I need to send them as an array as described here:

    https://developer.rocket.chat/reference/api/rest-api/endpoints/rooms/roo...

    I have 2 files to describe the API to be used with HTTP Client Manager, these are:

    src/api/rocket_chat.yml

    name: "rocket.chat API"
    apiVersion: "1.0"
    description: "Client wrapper for the rocket.chat API."
    imports:
      - "resources/rooms.yml"
    

    src/api/resources/rooms.yml

    operations:
      CreateDiscussion:
        httpMethod: "POST"
        uri: "rooms.createDiscussion"
        summary: "Create discussion"
        parameters:
          X-Auth-Token:
            location: "header"
            default: "token"
          X-User-Id:
            location: "header"
            default: "userid"
          Content-Type:
            location: "header"
            default: "application/json"
          prid:
            type: "string"
            location: "json"
            description: "Parent room ID of the discussion."
            required: true
          t_name:
            type: "string"
            location: "json"
            description: "Discussion name."
            required: true
          users:
            type: "array"
            location: "json"
            description: "Array of users to join in the discussion, if not provided, it will be an empty array. (Note: if provided, it must be an array)."
            required: false
            default: []
            items:
              "$ref": "Users"
          pmid:
            type: "string"
            location: "json"
            description: "Parent message ID (if the discussion comes from a message)."
            required: false
          reply:
            type: "string"
            location: "json"
            description: "The reply of the discussion."
            required: false
        responseModel: "CreateDiscussionResult"
    models:
      Users:
        type: "string"
        location: "json"
      CreateDiscussionResult:
        type: "object"
        location: "json"
        properties:
          success:
            location: "json"
            type: "boolean"
          discussion:
            location: "json"
            type: "object"
    

    My testing model in BPMN.iO for ECA looks like this:

    And this is what my action looks like:

    The php error that I have mentioned above, occurs because I don't know how to send the users as an array. In the previous image I have tested with: [ "foo", "bar", "test" ]

  • 🇩🇪Germany jurgenhaas Gottmadingen

    That sounds like an issue for the HTTP Client Manager module then. The action plugin expects an array, but a config form can only always receive strings. So, that action plugin needs to be modified such that it converts the input into an array after it has received an encoded string, e.g. as json or yaml.

  • Status changed to Closed: works as designed 8 months ago
  • 🇮🇹Italy aronne

    Hi @ovilla,
    the HttpConfigRequestForm class converts strings written in JSON format to array and objects.
    That's why it works when you use Http Config Requests written by using their original form.
    I don't know how BPM.io is building this form but I think it's missing this "little" part

          // ...
    
          case 'array':
          case 'object':
            $element['#type'] = 'textarea';
            $element['#rows'] = 12;
            $element['#description'] .= '<div class="json-help">' . $this->t('Example') . ': <small><pre>' . $this->getJsonHelp($param) . '</pre></small></div>';
            $element['#attributes']['placeholder'] = $this->t('Enter data in JSON format.');
            $element['#value_callback'] = [$this, 'jsonString'];
            $element['#element_validate'][] = [
              $this,
              'validateJson',
            ];
            break;
    
            //....
    

    I don't think this problem is caused by HTTP Client Manager module itself since it works fine on this side.

Production build 0.71.5 2024