<!DOCTYPE html>
<html>
<body>
<div id="my-am-designer" class="am-designer"></div>
<div id="my-am-flow-manager" class="am-flow-manager-container"></div>
<script src="./appmixer.js"></script>
<script>
var appmixer = new Appmixer({ baseUrl: 'https://api.qa.appmixer.com' });
var yourUserUsername = '123ABC45678@example.com'; // User ID of the user in YOUR system (must be in an email format!).
var appmixerUserPassword = '[POPULATE_FROM_YOUR_DB]'; // A password of the virtual user in Appmixer.
appmixer.api.authenticateUser(yourUserUsername, appmixerUserPassword).then(function(auth) {
appmixer.set('accessToken', { token: auth.token, userId: auth.user.id });
onAppmixerReady();
}).catch(function(err) {
if (err.response && err.response.status === 403) {
// Virtual user not yet created in Appmixer. Create one with a random password and save the password in YOUR system
// so that you can authenticate the user later.
appmixerUserPassword = Math.random().toString(36).slice(-8);
appmixer.api.signupUser(yourUserUsername, appmixerUserPassword).then(function(auth) {
appmixer.set('accessToken', { token: auth.token, userId: auth.user.id });
// ... Store auth.token and appmixerUserPassword in your DB.
onAppmixerReady();
}).catch(function(err) {
alert('Something went wrong.');
});
} else {
alert('Something went wrong.');
}
});
function onAppmixerReady() {
var designer = appmixer.ui.Designer({ el: '#my-am-designer' });
var flowManager = appmixer.ui.FlowManager({ el: '#my-am-flow-manager' });
flowManager.open();
flowManager.on('flow:open', function(flowId) {
designer.set('flowId', flowId);
flowManager.close();
designer.open();
});
flowManager.on('flow:create', function() {
flowManager.state('loader', true);
appmixer.api.createFlow('New Flow').then(function(flowId) {
designer.set('flowId', flowId);
flowManager.close();
designer.open();
}).catch(function(err) {
flowManager.state('error', 'Error creating a new flow.');
});
});
}
</script>
</body>
</html>