Create Customers via API & add them to a Group

I was looking at the API example and i see i can create customers easy enough but i wish to add them to a certain group once created. Can this be done?? If so how do i do it??

Would it be as easy as the running the following SQL statement after the account has been created

UPDATE `myonline_mailwizz`.`mw_customer` SET `group_id` = '4' WHERE `mw_customer`.`email` =NEW_CUSTOMERS_EMAIL;
 
Last edited:
Hey Guys... maybe you can help me here.... I've included the snippet that sets up the group_id. All other parameters are sent through the API and it creates a customer... but the customer that is created has a 'null' value for group_id in the database. Any suggestions? I'm sure I'm doing something wrong.

~~~~

// GRAB VARIABLES
$firstname = ucwords($_GET['firstname']);
$lastname = ucwords($_GET['lastname']);
$email = $_GET['email'];
$group_id = (int) $_GET['groupid'];

echo 'First Name: ' . $firstname . ' <br />';
echo 'Last Name: ' . $lastname . ' <br />';
echo 'Email: ' . $email . ' <br />';
echo 'Group ID: ' . $group_id . ' <br />';

// CREATE CUSTOMER
$response = $endpoint->create(array(
'customer' => array(
'first_name' => $firstname,
'last_name' => $lastname,
'email' => $email,
'password' => 'passwordgoeshere',
'timezone' => 'America/Los_Angeles',
'group_id' => $group_id
)

~~~

Thank you!

-bradley
 
Last edited:
@twisted1919 - First off, thank you for the reply! I appreciate all the hard work you've put into this script.

Regarding your responses -> Yes. I'm sure the group_id is correct. I did more testing and this is what I seem to have discovered....

1. If "registration" isn't enabled in the Settings >> Customers >> Registration page, it doesn't work at all.
2. Whatever is set in the Settings >> Customers >> Registration >> Default Group overrides the group_id I'm trying to set with the API

I could use some guidance here. I'd like not to have my page open to anyone that wants to register, but I'd like to have the ability to register people into different groups based on different landing pages and criteria that I set. Can you help me work through that?

Thank you!

-bradley
 
@Bradley - i got a chance to look over and do some tests and seems we don't allow group_id anymore because this would allow someone to register in whatever group they want which is not really okay.
However, if you edit the file apps/common/models/Customer.php, and you edit line 144 from:
PHP:
array('group_id, status', 'unsafe', 'on' => 'update-profile, register'),
to
PHP:
array('status', 'unsafe', 'on' => 'update-profile, register'),

Then your group will save just fine.
 
Back
Top