I've been trying to setup a usage of Rules with wsclient and have encountered a problem with data types. I've defined a custom module which implements hook_default_wsclient_service. It's working ok and calling the appropriate services which I can see via a reverse proxy. However, it seems to have some problems interpreting the responses inside the extensions to Rules.

I've defined this data type which is returned from a rest API in XML and I'm using HttpClientXMLFormatter. I can see it getting valid values back for reasons I'll go into next. Here is an example of a data type I'm defining:

$service->datatypes = array(
    'user' => array(
        'label' => 'User',
        'property info' => array(
            'id' => array(
                'type' => 'text',
                'label' => 'User ID',
            ),
            'account_id' => array(
                'type' => 'decimal',
                'label' => 'Account ID',
            ),
        ),
    ),
);

This information is coming from a third party and I want to store those user IDs and account IDs against my drupal users. I've setup a few custom fields using the profile2 module - one decimal, one text, on integer. No matter what I tried to do inside Rules to set values coming back from wsclient on my users, it always gives "Unable to modify data "account:XXXX": Invalid data value given. Be sure it matches the required data type and format." But in the data selection widget, Drupal/Rules is correctly recognising the fields I want to use as the correct data type. It just won't set the data when the call is executed.

I managed to find a workaround and so I know values are coming through. I created this action setup within Rules and it set the value correctly:

  1. Call the REST service and store result in "result"
  2. Convert data type, Target type: Text, Value to convert: [result:account-id] and store in variable account_id_as_text
  3. Set a data value, [account:field-custom-field-X], Value: [account-id-as-text]

This works fine! But needless to say it's a hassle and does mean I have to assign some incorrect data type inside my wsclient definition.

So to summarise:

  1. Getting a decimal attribute from the REST service and storing in a decimal account field doesn't seem to work, although Rules/Drupal correctly recognises it as a valid I can populate there.
  2. Getting a text attribute from the REST service and storing in a decimal account field doesn't seem to work, although Rules/Drupal correctly recognises it as a valid I can populate there.
  3. Getting a decimal attribute from the REST service and first converting it using Rules into a text field and only then storing in a text account field seems to work fine.

Sounds to me like it could be a Rules module problem. What do you think?

Comments

ptmkenny’s picture

Is it possible for you to list exact steps to reproduce this on a clean install of the latest version of Drupal and Rules without unnecessary additional modules enabled?

ptmkenny’s picture

Status: Active » Postponed (maintainer needs more info)
TR’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

No further information provided.