You are here

You are here

Find user and list group memberships

A common scenario is to search for a user and retrieve some information about them.  This example searches for a user and if the user is found, displays the user's group memberships.
Note:  Even though the method names are ContactFind and GroupGetByContact, they will work with both SCMContact and SCMUserAccount objects.

Vertical Tabs

c#
SCMContactInfo[] users = springCMService.ContactFind(token, "jdoe@springcm.com", false);
 
if (users.Count() == 1)
{
    Console.WriteLine("User First Name: {0}", users[0].FirstName);
    Console.WriteLine("User Last Name: {0}", users[0].LastName);
    SCMGroup[] groups = service.GroupGetByContact(token, users[0]);
 
    Console.WriteLine("Group Memberships:");
    for (int i = 0; i < groups.Length; i++)
    {
        Console.WriteLine(groups[i].Name);
    }
}
java
SCMContactInfo[] users = springCMService.contactFind(token, "jdoe@springcm.com", false);
 
if (users.length == 1)
{
    System.out.println("User First Name: " + users[0].getFirstName());
    System.out.println("User Last Name: " + users[0].getLastName());
    SCMGroup[] groups = springCMService.groupGetByContact(token, users[0]);
 
    System.out.println("Group Memberships:");
    for (inti = 0; i<groups.length; i++)
    {
        System.out.println(groups[i].getName());
    }
}
php
<?php
 
// The GroupGetByContact method requires that we pass it an object derived from
// SCMContactInfo
// In order to use derived objects against a WSDL in PHP, we have to set up the class hierarchy
$classMap = array('SCMContactInfo'=>'ContactInfo', 
                  'SCMUserAccount'=>'UserAccount', 
                  'SCMContact'=>'Contact');
 
// The parent class ContactInfo has numerous fields, but Id is the only one that's required
class ContactInfo {
	public $Id;
}
 
// Contact does not have any required fields beyond what's on ContactInfo
class Contact extends ContactInfo {}
 
// Role and Status are required fields on a UserAccount object; the rest can be left null
class UserAccount extends ContactInfo
{
	public $Role;
	public $Status;
}
 
// pass the class mapping into the SoapClient;
$springCM = new SoapClient('https://soapna11.springcm.com/atlas/webservices/v201305/springcmservice.asmx?wsdl',
	array('classmap'=>$classMap)); 
 
$authResult = $springCM->AuthenticateNonDefault( array(
	'userName'=>'<your id>',
	'password'=>'<your password>',
	'AccountId'=>'<your account id>',
	'apiKey'=>'<your api key>'
));
 
// Get the inner object from the SOAP response
$token = $authResult->AuthenticateNonDefaultResult;
 
$userToFind = '<email address of the user to find>';
 
$userObject = $springCM->ContactFind( array(
	'token'=>$token,
	'SearchText'=>$userToFind,
	'IncludeDeleted'=>false
));
 
// Get the inner object from the SOAP response
$userObject = $userObject->ContactFindResult;
 
if ($userObject->ContactInfo != null);
{
	$userAccount = new UserAccount();
	// Populate required fields from the retrieved record
	$userAccount->Id = $userObject->SCMContactInfo->Id;
	$userAccount->Role = $userObject->SCMContactInfo->Role;
	$userAccount->Status = $userObject->SCMContactInfo->Status;
 
	$groupsResult = $springCM->GroupGetByContact( array(
		'token'=>$token,
		'contact'=>$userAccount
	));
}
 
?>