Problem with createUpdate function API when import contacts

Ruben Toledo

New Member
Hello,
I have a timing issue with an external application.
I am using the API, specifically with createUpdate or update function to import contacts from my application to list mailwizz.
The problem is this: I created in the list of mailwizz an extra field, my external contacts application does not have this field. When I update an existing contact, me clears the value of this field mailwizz list.
Is there any way that this field is not overwritten?
 

twisted1919

Administrator
Staff member
Might be too much, but what if you fetch the subscriber first, and merge existing data with the new data and then make the update call?
 

twisted1919

Administrator
Staff member
Or even better.

apps/api/controllers/List_subscribersController.php at around line 555 you have this foreach:
PHP:
     foreach ($fields as $field) {
            $valueModel = ListFieldValue::model()->findByAttributes(array(
                'field_id'        => $field->field_id,
                'subscriber_id'    => $subscriber->subscriber_id,
            ));

            if (empty($valueModel)) {
                $valueModel = new ListFieldValue();
                $valueModel->field_id = $field->field_id;
                $valueModel->subscriber_id = $subscriber->subscriber_id;
            }

            $valueModel->value = $substr($request->getPut($field->tag), 0, 255);
            $valueModel->save();
        }

make it:

PHP:
     foreach ($fields as $field) {
            $fieldValue = $request->getPut($field->tag, null);

            // if the field has not been sent, skip it.
            if ($fieldValue === null) {
                continue;
            }

            $valueModel = ListFieldValue::model()->findByAttributes(array(
                'field_id'        => $field->field_id,
                'subscriber_id'    => $subscriber->subscriber_id,
            ));

            if (empty($valueModel)) {
                $valueModel = new ListFieldValue();
                $valueModel->field_id = $field->field_id;
                $valueModel->subscriber_id = $subscriber->subscriber_id;
            }

            $valueModel->value = $substr($fieldValue, 0, 255);
            $valueModel->save();
        }

This is a safe change since will be included in next release.[/php]
 
Top