In order to create your first user will first need to have PHP installed and be able to run it from the command line. See the articles below for help:
- Installation: http://php.net/manual/en/install.php
- Windows: http://php.net/manual/en/install.windows.commandline.php
- Mac: http://php.net/manual/en/features.commandline.php
- Linux: http://php.net/manual/en/features.commandline.php
Installing the Mambo PHP SDK
Once you have PHP installed and running, you will need to download the Mambo PHP SDK. You can find the SDK here:
- Sandbox: http://api.mambo.io/#docs/downloads/php-sdk
- Your installation: http://YOUR_MAMBO_URL/#docs/downloads/php-sdk
Replace YOUR_MAMBO_URL with the address to your Mambo platform installation, for example: http://mydomain.com.
Unzip the files from the PHP SDK and add them to a folder into which we will also add the UserScript.php that you're going to be creating below.
Adding the Script to Create the User
Once you have downloaded the Mambo PHP SDK you will need to create an empty text file called UserScript.php. In this file you are going to copy the PHP code below:
<?php // Import the library files require_once('/sdk/Mambo.php'); // Uncomment the line below to receive the API response in Portuguese. By default English is used. // MamboClient::$acceptLanguage = "pt"; // Initialise the clients credentials and end point URL, this only needs to be done once MamboClient::setCredentials( "YOUR_PUBLIC_KEY", "YOUR_PRIVATE_KEY" ); MamboClient::setEndPointBaseUrl( "YOUR_MAMBO_URL" ); // Prepare the request data used to create the user $data = new UserRequestData(); $data->setUuid( '0001' ); // Required $data->setPictureUrl( "" ); $data->setProfileUrl( "" ); $data->setIsMember( true ); // Prepare the user details $details = new UserDetails(); $details->setEmail( "email@example.com" ); // Required $details->setFirstName( "John" ); // Required $details->setLastName( "Doe" ); // Required $details->setBirthday( "1982-03-24T00:01:32.876Z" ); // Required - Please use the format indicated $details->setGender( "M" ); // Required - Valid genders: M / F / U (M = Male, F = Female, U = Unknown) $details->setDisplayName( "John" ); $data->setDetails( $details ); // Prepare the user's Facebook details //$facebook = new FacebookDetails(); //$facebook->setFacebookId( "facebookId" ); //$facebook->setFacebookUrl( "http://www.facebook.com/page" ); //$data->setFacebook( $facebook ); // Prepare the user's Twitter details //$twitter = new TwitterDetails(); //$twitter->setTwitterId( "twitterId" ); //$twitter->setTwitterUrl( "http://www.twitter.com/yourid" ); //$twitter->setTwitterUser( "twitterUser" ); //$data->setTwitter( $twitter ); // Create the user $user = MamboUsersService::create( 'YOUR_SITE_URL', $data ); var_dump( $user ); ?>
You will need to fill in the missing information from the file before you can run it and create a user. The missing information can be found here:
- YOUR_PRIVATE_KEY: http://api.mambo.io/#dev/keys
- YOUR_PUBLIC_KEY: http://api.mambo.io/#dev/keys
- YOUR_MAMBO_URL: this is the address to your own mambo installation. If you have access to the sandbox and would like to create a user there, then use: http://api.mambo.io
- YOUR_SITE_URL: this is the URL value of the site you created in the Mambo platform. The list of sites you created can be found here: http://api.mambo.io/#config/sites
The addresses above are all for the Mambo Sandbox environment. If you'd like to use your own documentation or don't have access to the sandbox environment then replace the "api.mambo.io" portion of the address with your own Mambo installation's address e.g. "mambo.mydomain.com".
Putting it all together
All you need to do now is run your UserScript.php from the command line. Open the command line, navigate to the folder where there script is saved and type:
That's it! You're all done.
Now if you want to create more users, simply open the UserScript.php file and edit the value in the setUuid("0001") method to a new UUID.
If you receive an error back in the command line, then the error should provide you information explaining what went wrong. For example, the API keys aren't correct, or the Site Url could not be found.