Add a User to an Account
Adding a user to your existing account allows you to provide access to the account to a new person while also regulating what actions that user can perform. You can perform this action via the SOAP API to add new users to accounts owned by embedded partners, or you can use this code to add users from information taken from third-party sources, such as HR systems.
The user's permissions determine which actions a user can perform and what information they can view within an account.
Be sure to have the correct username and password information for the new user for use in the creation process. Avoid using XML-sensitive characters such as #, ^, <, >, or & in the password.
Code Example
Use these code examples to model your requests. These examples include the required attributes for each user using the AccountUser object.
Java Example
1 public void testAddUserToAccount ( )
2 {
3 Account account = new Account ( ) ;
4 Account . ID = 12334 ;
5 if ( account != null )
6 {
7 AccountUser accountUser = new AccountUser ( ) ;
8 accountUser . Name = "ACRUZ" ;
9 accountUser . UserID = "ACRUZ" ;
10 accountUser . IsAPIUser = true ;
11 accountUser . IsAPIUserSpecified = true ;
12 accountUser . IsLocked = false ;
13 accountUser . IsLockedSpecified = true ;
14 accountUser . Password = "XXX" ;
15 accountUser . MustChangePassword = false ;
16 accountUser . MustChangePasswordSpecified = true ;
17 accountUser . Email = "acruz@example.com" ;
18 UserAccess access = new UserAccess ( ) ;
19 //3 CLIENT_ADMIN Add Users to Account
20 //4 PRO_ADMIN Create/View Accounts
21 access . ID = 3 ;
22 access . IDSpecified = true ; //.Net specific
23 accountUser . UserPermissions = new UserAccess [ ] { access } ;
24 //This tells that create user in subaccount
25 ClientID clientID = new ClientID ( ) ;
26 clientID . PartnerClientKey = "12345" ;
27 clientID . IDSpecified = true ;
28 accountUser . Client = clientID;
29 APIObject [ ] apiObjects = { accountUser } ;
30 String requestId = null ;
31 String overAllStatus = null ;
32 CreateResult [ ] results = partnerAPIWse . Create ( new CreateOptions ( ) , apiObjects, out requestId, out overAllStatus ) ;
33 if ( results != null )
34 {
35 foreach ( CreateResult result in results )
36 {
37 Console . WriteLine ( ) ;
38 Console . WriteLine ( "Status Message ### " +
39 result . StatusMessage ) ;
40 }
41 }
42 else
43 {
44 Console . Write ( "Error ...... " ) ;
45 }
46 }
47 }
When dealing with Single Sign-on functionality, you can add this information to the example:
1 SsoIdentity sso = new SsoIdentity();
2 sso.Active = true;
3 sso.FederatedID = ;
4 accountUser.Ssoidentities = new SsoIdentity[] {sso};
Sample Java Code (Axis 1.4)
1 private CreateResponse createUserForThisAccount(Soap stub, Account account) throws java.rmi.RemoteException {
2
3 CreateRequest request;
4 APIObject[] apiObjects = null;
5 CreateResponse response;
6 AccountUser accountUser = new AccountUser();
7 accountUser.setUserID("AngelCruz");
8 accountUser.setPassword("XXX");
9 accountUser.setName("Angel Cruz");
10 accountUser.setEmail("acruz@example.com");
11 accountUser.setIsAPIUser(true);
12 accountUser.setIsLocked(false);
13 UserAccess access1 = new UserAccess();
14 access1.setID(23);
15 UserAccess access2 = new UserAccess();
16 access2.setID(3);
17 UserAccess access3 = new UserAccess();
18 access3.setID(25);
19 ClientID clientID = new ClientID();
20 clientID.setID(account.getID());
21 accountUser.setClient(clientID);
22
23 request = new CreateRequest();
24 apiObjects = new AccountUser[]{accountUser};
25 request.setObjects(apiObjects);
26 request.setOptions(new CreateOptions());
27 response = stub.create(request);
28 return response;
29 }
Sample SOAP Envelope
1 <createrequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
2 <objects xsi:type="AccountUser">
3 <partnerkey xsi:nil="true"></partnerkey>
4 <objectid xsi:nil="true"></objectid>
5 <client>
6 <id>12345</id>
7 </client>
8 <userid>ACRUZ</userid>
9 <password>XXX</password>
10 <name>ACRUZ</name>
11 <email>acruz@example.com</email>
12 <activeflag>true</activeflag>
13 <isapiuserspecified>true</isapiuserspecified>
14 <isapiuser>true</isapiuser>
15 <islockedspecified>true</islockedspecified>
16 <islocked>true</islocked>
17 <mustchangepassword>true</mustchangepassword>
18 <mustchangepasswordspecified>true</mustchangepasswordspecified>
19 <defaultbusinessunit>12345</defaultbusinessunit>
20 <userpermissions>
21 <useraccess>
22 <id>3</id>
23 <idspecified>true</idspecified>
24 </useraccess>
25 </userpermissions>
26 <ssoidentities>
27 <Ssoidentity>
28 <isactive>true</isactive>
29 <federatedid>ACRUZ</federatedid>
30 </Ssoidentity>
31 </ssoidentities>
32 </objects>
33 </createrequest>
Related Items