Snippets
Created by
Monil Gandhi
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | const util = require('util');
var Braango = require('braango');
var defaultClient = Braango.ApiClient.instance;
/**
*
* @author braango
*
* Code to create virtual dealer for partner having valid auth_token
*
* Auth token of master account is generated by sales team. Allows master
* account holder to manage either partner_dealer(s) or real
* hierarchical dealers. This example assumes virtual dealer mode where
* master account is simply container to hold
* "partner_dealer (virtual dealer)" account "partner_dealer" account
* acts as empty proxy dealership
*
* "partner_dealer" will hold dealers which are called "subDealers" and
* their personnel
*
*/
//TEST auth token. Please contact
//sales@braango.com to have one
//created for you
var auth_token = defaultClient.authentications['auth_token'];
auth_token.apiKey = "ISNWF0P30WM0CMK";
var apiInstance = new Braango.AccountsApi();
var opts = {
'body': new Braango.AccountCreateRequestInput() // AccountCreateRequestInput |
};
//var opts = new Braango.AccountCreateRequestInput();
/*
* { "api_key": "ISNGvAzwuy4X7vAqrtV", "id": "any value",
* "account_type": "partner" }
*/
var requestHeader = new Braango.RequestHeader();
//console.log(requestHeader instanceof Braango.RequestHeader);
//Set the account type to partner for
//virtual dealer and partner hosted
//accounts
requestHeader['account_type'] = "partner";
//This id for your tracking, will be reflected back in response.
//Doesn't get used by Braango
//If not speficied, braango will return session-id in its response
requestHeader['id'] = "create-partner-dealer-p7";
opts["body"]["header"] = requestHeader;
//Actual body of the virtual dealer object
var accountInput = new Braango.AccountInput();
//Business name - Required. Needs to be unique within
//Braango system. Braango will return error code if
//name conflicts
accountInput['business_name'] = "partner p9";
//username is needed for dashboard login and in future
//will be used for basic auth - Required
accountInput['user_name'] = "partnerp9";
/*
* Password will be encrypted with SHA-25 and base64 encoded and stored
* internally within the braango system. pattern:
* ^(?=^.{6,10}$)(?=.*\d)(
* ?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()_+}{"
* ;:;'?/>.<,])(?!.*\s).*$
*
* Used for single sign on. needs to 6-10 characters with one capital,
* one numberal and one special character
*/
accountInput['password'] = "p9Partner$";
//First name of authorized user - Required
accountInput['first_name'] = "partnerp9";
//Last name of authorized user - Required
accountInput['last_name'] = "partnerp9";
//Required
accountInput['email'] = "partner@partner9.com";
//Required
accountInput['cell_phone'] = "4087651238";
//Required
//For virtual dealer, always select enterprise
accountInput['package'] = "Franchise";
//Creating virtual dealer - Optional
accountInput['virtual_dealer'] = 'true';
opts['body']["body"] = accountInput;
apiInstance.createPartnerDealer(opts).then(function(data) {
console.log('API called successfully. Returned data: ' + util.inspect(data, false, null));
}, function(error) {
console.error(error);
});
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.