<p>You can use the controller endpoint that's also used for public registrations as described in the knowledge base article on <a href="https://craftcms.com/knowledge-base/front-end-user-accounts" rel="nofollow noreferrer">Front-End User Accounts</a>. But instead of providing an HTML form on your site, you're going to trigger the request to the controller endpoint from PHP, probably from a hook in your WordPress site. First, make sure that the setting to <em>Allow public registration</em> is on to allow unauthenticated requests to create new accounts.</p>
<p>You can execute the request however you like, here's an example using <a href="https://docs.guzzlephp.org/en/stable/" rel="nofollow noreferrer">Guzzle</a> (might need some adjustments).</p>
<pre class="lang-php prettyprint-override"><code>$client = new GuzzleHttp\Client(['base_uri' =&gt; 'https://your-site.com']);

$response = $client-&gt;post('actions/users/save-user', [
    'form_params' =&gt; [
        'username' =&gt; 'alice-foobar',
        'firstName' =&gt; 'Alice',
        'lastName' =&gt; 'Foobar',
        'email' =&gt; 'alice@example.com',
        // …
    ],
]);

$statusCode = $response-&gt;getStatusCode();
</code></pre>
<p>You're probably gonna need to provide a CSRF token as well. In this case, make a request to <a href="https://docs.craftcms.com/api/v3/craft-controllers-userscontroller.html#method-actionsessioninfo" rel="nofollow noreferrer"><code>users/session-info</code></a> first to get a valid token and then pass it back to the POST request.</p>
<p>Using this approach you can perform additional methods like saving user data and adding entries / enrollment information. Note that most controller methods will require authentication. You can also provide a <a href="https://craftcms.com/docs/3.x/extend/controllers.html" rel="nofollow noreferrer">custom controller endpoint</a> to perform all those steps in one go, implementing whatever authentication method you deem appropriate.</p>

CC BY-SA 4.0
2022-04-08T09:05:51.693Z
2022-04-08T09:05:51.693Z
MoritzLost
<p>I'm a junior web developer working with Craft CMS.</p>
<p>I was wondering if there was a way to trigger a controller I have for my Craft CMS from an outside CMS. We have more than one website that offers online trainings for people to purchase, but the course itself is hosted on our Craft CMS.</p>
<p>I'm hoping to achieve this:</p>
<ol>
<li>A person purchases a course from our Wordpress site.</li>
<li>After successful purchase, it triggers a request to our Craft CMS which creates an account and then enrolls them in the course.</li>
</ol>
<p>I'm not sure how to go about it...</p>
<p>Appreciate any insight on this matter. Thank you.</p>

<plugin-development><users><multi-site><controller><routing>
Is there a way to trigger a user account creation from a different CMS?
# Is there a way to trigger a user account creation from a different CMS?

(Asked by: username_0 on 2022-04-08)

I'm a junior web developer working with Craft CMS.

I was wondering if there was a way to trigger a controller I have for my Craft CMS from an outside CMS. We have more than one website that offers online trainings for people to purchase, but the course itself is hosted on our Craft CMS.

I'm hoping to achieve this:

1. A person purchases a course from our Wordpress site.
2. After successful purchase, it triggers a request to our Craft CMS which creates an account and then enrolls them in the course.

I'm not sure how to go about it...

Appreciate any insight on this matter. Thank you.

**Tags:** plugin-development, users, multi-site, controller, routing


---

## 1 answers

### Answer by username_1 on 2022-04-08. Score: 2

You can use the controller endpoint that's also used for public registrations as described in the knowledge base article on Front-End User Accounts. But instead of providing an HTML form on your site, you're going to trigger the request to the controller endpoint from PHP, probably from a hook in your WordPress site. First, make sure that the setting to Allow public registration is on to allow unauthenticated requests to create new accounts.
You can execute the request however you like, here's an example using Guzzle (might need some adjustments).
$client = new GuzzleHttp\Client(['base_uri' => 'https://your-site.com']);

$response = $client->post('actions/users/save-user', [
    'form_params' => [
        'username' => 'alice-foobar',
        'firstName' => 'Alice',
        'lastName' => 'Foobar',
        'email' => 'alice@example.com',
        // …
    ],
]);

$statusCode = $response->getStatusCode();

You're probably gonna need to provide a CSRF token as well. In this case, make a request to users/session-info first to get a valid token and then pass it back to the POST request.
Using this approach you can perform additional methods like saving user data and adding entries / enrollment information. Note that most controller methods will require authentication. You can also provide a custom controller endpoint to perform all those steps in one go, implementing whatever authentication method you deem appropriate.


---

