Creates a new user impersonation session.
Arguments
employeeEmail string required
The email of the employee who is performing the impersonation
targetUserId string required
The ID of the user to be impersonated
userAgent string required
The user agent of the employee performing the impersonation
ipAddress string required
The IP address of the employee performing the impersonation
metadata JsonValue
Any additional metadata to attach to the impersonation session
Successful Response
sessionId string
The unique identifier for the impersonation session
impersonationSessionToken string
The token to use for authenticating as the impersonated user
expiresAt number
Unix timestamp when the impersonation session expires
Error Types
ImpersonationDisabled
Impersonation is disabled for this organization
UnauthorizedEmployee
The provided employee is not authorized to perform impersonation
UnexpectedError
An unexpected error occurred during the operation
const auth = createClient({ url, integrationKey });
const result = await auth.impersonation.create({ employeeEmail: "example@acmeinc.com", targetUserId: "1189c444-8a2d-4c41-8b4b-ae43ce79a492", userAgent: "Mozilla/5.0 (Macintosh...", ipAddress: "136.38.37.199", metadata: { "example": "value" }});
if (result.ok) { console.log("Impersonation session created successfully"); console.log("Session ID:", result.data.sessionId); console.log("Token:", result.data.impersonationSessionToken);} else { console.log(`Error: ${result.error}`); // Check result.error.type to handle specific errors}client = create_client(url=url, integration_key=integration_key)
result = await client.impersonation.create( employee_email="example@acmeinc.com", target_user_id="1189c444-8a2d-4c41-8b4b-ae43ce79a492", user_agent="Mozilla/5.0 (Macintosh...", ip_address="136.38.37.199", metadata={ "example": "value" })
if is_ok(result): print("Impersonation session created successfully") print(f"Session ID: {result.data.session_id}") print(f"Token: {result.data.impersonation_session_token}")else: print(f"Error: {result.error}") # Check result.error.type to handle specific errorsclient, err := byo.NewClient(url, integrationKey)if err != nil { log.Fatal(err)}
result, err := client.Impersonation.Create(ctx, byo.CreateImpersonationSessionCommand{ EmployeeEmail: "example@acmeinc.com", TargetUserID: "1189c444-8a2d-4c41-8b4b-ae43ce79a492", UserAgent: "Mozilla/5.0 (Macintosh...", IPAddress: "136.38.37.199", Metadata: map[string]any{ "example": "value", },})if err != nil { log.Fatal(err)}
fmt.Println(result.ImpersonationSessionToken)PropelAuthClient client = PropelAuthClient.create(url, integrationKey);
CreateImpersonationSessionCommand command = CreateImpersonationSessionCommand.builder() .employeeEmail("example@acmeinc.com") .targetUserId("1189c444-8a2d-4c41-8b4b-ae43ce79a492") .userAgent("Mozilla/5.0 (Macintosh...") .ipAddress("136.38.37.199") .metadata(JsonValue.of(Map.of("example", "value"))) .build();
try { CreateImpersonationSessionResponse response = client.impersonation.create(command); System.out.println("Impersonation session created successfully"); System.out.println("Session ID: " + response.getSessionId()); System.out.println("Token: " + response.getImpersonationSessionToken());} catch (CreateImpersonationSessionException.UnauthorizedEmployee e) { System.out.println("Unauthorized employee: " + e.getDetails());} catch (CreateImpersonationSessionException e) { System.out.println("Error: " + e.getMessage());}var client = new PropelAuthClient(new PropelAuthOptions{ Url = url, IntegrationKey = integrationKey});
var command = new CreateImpersonationSessionCommand{ EmployeeEmail = "example@acmeinc.com", TargetUserId = "1189c444-8a2d-4c41-8b4b-ae43ce79a492", UserAgent = "Mozilla/5.0 (Macintosh...", IpAddress = "136.38.37.199", Metadata = JsonSerializer.SerializeToElement(new { example = "value" })};
try{ var response = await client.Impersonation.CreateAsync(command); Console.WriteLine("Impersonation session created successfully"); Console.WriteLine($"Session ID: {response.SessionId}"); Console.WriteLine($"Token: {response.ImpersonationSessionToken}");}catch (CreateImpersonationSessionException.UnauthorizedEmployee ex){ Console.WriteLine($"Unauthorized employee: {ex.Details}");}catch (CreateImpersonationSessionException ex){ Console.WriteLine($"Error: {ex.Message}");}
Response
{ ok: true, data: { sessionId: "l5NeYIUscTuVZz7GriwydE", impersonationSessionToken: "impersonate_l5NeYI...", expiresAt: 1756846846 }}Result( data=CreateImpersonationSessionResponse( session_id="l5NeYIUscTuVZz7GriwydE", impersonation_session_token="impersonate_l5NeYI...", expires_at=1756846846 ))byo.CreateImpersonationSessionResponse{ SessionID: "l5NeYIUscTuVZz7GriwydE", ImpersonationSessionToken: "impersonate_l5NeYI...", ExpiresAt: 1756846846,}CreateImpersonationSessionResponse( sessionId="l5NeYIUscTuVZz7GriwydE", impersonationSessionToken="impersonate_l5NeYI...", expiresAt=1756846846)CreateImpersonationSessionResponse{ SessionId = "l5NeYIUscTuVZz7GriwydE", ImpersonationSessionToken = "impersonate_l5NeYI...", ExpiresAt = 1756846846}