<p>You could write a <a href="https://pluginfactory.io" rel="nofollow noreferrer">custom plugin</a> that exposed a <a href="https://craftcms.com/docs/plugins/controllers#allowing-anonymous-access-to-actions" rel="nofollow noreferrer">anonymous controller</a> endpoint that accepted to the user info you want to save.</p>

<p>From there the controller endpoint could create a new UserModel, populate necessary fields/properties you want to save, then call <a href="https://craftcms.com/classreference/services/UsersService#saveUser-detail" rel="nofollow noreferrer"><code>craft()-&gt;users-&gt;saveUser()</code></a> and let Craft do the database populating.</p>

CC BY-SA 3.0
2017-03-07T19:03:45.430Z
Thanks Brad. Sounds like the smarter way is to do through the Craft `saveUser()` action, versus writing to the db directly.
Nathan D Huening
CC BY-SA 3.0
2017-03-07T19:50:47.440Z
It's probably the way I'd go.
Brad Bell
CC BY-SA 3.0
2017-03-06T23:43:44.657Z
2017-03-06T23:43:44.657Z
Brad Bell
<p>Is there a simple / best practice way for creating new users programatically? My specific use case involves capturing user data for online sales using a 3rd-party form with Stripe integration. When a user checks out and makes the purchase (not on the Craft site), I'd like to capture the data and generate a user account automatically <em>on</em> the Craft site.</p>

<p>My current idea, which should work, is to trigger Zapier to write a custom record (containing the user fields) to the MySQL database directly. I've done it before in other contexts but am curious if there's a better way?</p>

<users>
Adding users outside of CP or front-end registration form
# Adding users outside of CP or front-end registration form

(Asked by: username_0 on 2017-03-06)

Is there a simple / best practice way for creating new users programatically? My specific use case involves capturing user data for online sales using a 3rd-party form with Stripe integration. When a user checks out and makes the purchase (not on the Craft site), I'd like to capture the data and generate a user account automatically *on* the Craft site.

My current idea, which should work, is to trigger Zapier to write a custom record (containing the user fields) to the MySQL database directly. I've done it before in other contexts but am curious if there's a better way?

**Tags:** users

---

## 1 answers

### Answer by username_1 on 2017-03-06. Score: 2 | Accepted answer

You could write a [custom plugin](https://pluginfactory.io) that exposed a [anonymous controller](https://craftcms.com/docs/plugins/controllers#allowing-anonymous-access-to-actions) endpoint that accepted to the user info you want to save.

From there the controller endpoint could create a new UserModel, populate necessary fields/properties you want to save, then call [`craft()->users->saveUser()`](https://craftcms.com/classreference/services/UsersService#saveUser-detail) and let Craft do the database populating.

> **Comments:**
> **username_0**: Thanks Brad. Sounds like the smarter way is to do through the Craft `saveUser()` action, versus writing to the db directly.  
> **username_1**: It's probably the way I'd go.  

---

