createUpdate does not work

OliverMJ

New Member
SOLVED: I had to allow PUT and DELETE http requests on the server, next I also had a line in the htaccess that blocked the put command.
Code:
 RewriteCond %{REQUEST_METHOD} ^(connect|debug|move|put|trace|track) [NC]

Once I took put out of that line, createUpdate worked.

Posting solution here in case someone else runs into this problem.

Thanks to twisted1919 for thinking along.
========================= original question follow===========

How can I get it to update properly? See troubles below.

I am trying to update a subscriber with use of subscribe.php as follows and setup.php

I get this error code:
Code:
MailWizzApi_Params Object
(
    [_data:MailWizzApi_Params:private] => Array
        (
            [status] => success
            [data] => Array
                (
                    [count] => 1
                    [total_pages] => 1
                    [current_page] => 1
                    [next_page] =>
                    [prev_page] =>
                    [records] => Array
                        (
                            [0] => Array
                                (
                                    [subscriber_uid] => nxxxxx31g94c
                                    [EMAIL] => oliver@xxxxxxxx.com
                                    [FNAME] => John
                                    [LNAME] => Doe
                                    [status] => confirmed
                                    [source] => api
                                    [ip_address] => xx.xxx.xx.xxx
                                    [date_added] => 2019-02-13 09:18:09
                                )

                        )

                )

        )

    [_readOnly:MailWizzApi_Params:private] =>
)

MailWizzApi_Params Object
(
    [_data:MailWizzApi_Params:private] => Array
        (
            [status] => error
            [error] => Not Found
        )

    [_readOnly:MailWizzApi_Params:private] =>
)
Below you see the subscibe.php and setup.php

How can I get it to update properly?

Code:
<?php
require_once dirname(__FILE__) . '/setup.php';
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();
/*===================================================================================*/
// GET ALL ITEMS
//RFF: This can probably go, it is just to check if the connection works
$response = $endpoint->getSubscribers('xxxxxxxxxxxxxxx', $pageNumber = 1, $perPage = 10);
// DISPLAY RESPONSE
echo '<pre>';
print_r($response->body);
echo '</pre>';

// CREATE / UPDATE EXISTING SUBSCRIBER
//RFF: code below will have to be incorporated in the form to connect the form with Mailwizz
//I have now hardcoded this to check one entry added
$response = $endpoint->createUpdate('xxxxxxxxxxxxxxx', array(
    'EMAIL'    => 'oliver@xxxxxxxx.com',
    'FNAME'    => 'John',
    'LNAME'    => 'Doe Updated'
));
// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';

Code:
<?php
/**
 * This file contains an example of base setup for the MailWizzApi PHP-SDK.
 *
 * @author Serban George Cristian <cristian.serban@mailwizz.com>
 * @link http://www.mailwizz.com/
 * @copyright 2013-2017 http://www.mailwizz.com/
 */

//exit('COMMENT ME TO TEST THE EXAMPLES!');

// require the autoloader class if you haven't used composer to install the package
require_once dirname(__FILE__) . '/../MailWizzApi/Autoloader.php';

// register the autoloader if you haven't used composer to install the package
MailWizzApi_Autoloader::register();

// if using a framework that already uses an autoloading mechanism, like Yii for example,
// you can register the autoloader like:
// Yii::registerAutoloader(array('MailWizzApi_Autoloader', 'autoloader'), true);

/**
 * Notes:
 * If SSL present on the webhost, the api can be accessed via SSL as well (https://...).
 * A self signed SSL certificate will work just fine.
 * If the MailWizz powered website doesn't use clean urls,
 * make sure your apiUrl has the index.php part of url included, i.e:
 * http://www.mailwizz-powered-website.tld/api/index.php
 *
 * Configuration components:
 * The api for the MailWizz EMA is designed to return proper etags when GET requests are made.
 * We can use this to cache the request response in order to decrease loading time therefore improving performance.
 * In this case, we will need to use a cache component that will store the responses and a file cache will do it just fine.
 * Please see MailWizzApi/Cache for a list of available cache components and their usage.
 */

// configuration object
$config = new MailWizzApi_Config(array(
    'apiUrl'        => 'https://www.xxxxxxxxxxxxxxxxxx.xx/newsletter/api/index.php',
    'publicKey'     => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'privateKey'    => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',

    // components
    'components' => array(
        'cache' => array(
            'class'     => 'MailWizzApi_Cache_File',
            'filesPath' => dirname(__FILE__) . '/../MailWizzApi/Cache/data/cache', // make sure it is writable by webserver
        )
    ),
));

// now inject the configuration and we are ready to make api calls
MailWizzApi_Base::setConfig($config);

// start UTC
date_default_timezone_set('UTC');
 
Last edited:
Most likely your API url is not correct... that Not Found messages comes from your web server.
If you access the api url you have used, in your browser, does it work ?
 
Thanks for your answer.

Direct access to the api url works, it shows [] in the source.

When I make the connection with the subscribe.php as above, it does make a good connection.

I conclude that because it creates a new user to the specified list.

Also when I call the same page again, it lists the current subscribers to that list.

The trouble starts with the createUpdate part.

Once again here is the output if I go to the page again, and have it update the details, do you want me to PM the urls?


Code:
MailWizzApi_Params Object
(
    [_data:MailWizzApi_Params:private] => Array
        (
            [status] => success
            [data] => Array
                (
                    [count] => 1
                    [total_pages] => 1
                    [current_page] => 1
                    [next_page] =>
                    [prev_page] =>
                    [records] => Array
                        (
                            [0] => Array
                                (
                                    [subscriber_uid] => nxxxxx31g94c
                                    [EMAIL] => oliver@xxxxxxxx.com
                                    [FNAME] => John
                                    [LNAME] => Doe
                                    [status] => confirmed
                                    [source] => api
                                    [ip_address] => xx.xxx.xx.xxx
                                    [date_added] => 2019-02-13 09:18:09
                                )

                        )

                )

        )

    [_readOnly:MailWizzApi_Params:private] =>
)

MailWizzApi_Params Object
(
    [_data:MailWizzApi_Params:private] => Array
        (
            [status] => error
            [error] => Not Found
        )

    [_readOnly:MailWizzApi_Params:private] =>
)
 
Back
Top