Developer
Documentation
Resources
Get Support
Sign in
Developer
Get Support
Sign in
DOCUMENTATION
Cloud
Data Center
Resources
Sign in
Developer
Sign in
DOCUMENTATION
Cloud
Data Center
Resources
Sign in
Object operations
User operations
Group operations
Last updated Aug 18, 2025

setUsers

The Connector SDK APIs are available through Forge's Early Access Program (EAP).

EAPs are offered to selected users for testing and feedback purposes. We are currently working with a select group of EAP participants to get their apps production-ready and available for publishing on Marketplace.

To use the Connector SDK, you must be part of the Forge connector EAP. If you are interested in joining this EAP, you can express interest through this form.

The setUsers method allows you to bulk create or update users in the Teamwork Graph in a single API call. This is the recommended approach for bulk user ingestion as it's more efficient than making individual requests for each user.

Method signature

1
2
setUsers(request: BulkUsersRequest): Promise<BulkUsersResponse>

Parameter: request

  • Type: BulkUsersRequest
  • Required: Yes
  • Description: The bulk user ingestion request containing users
1
2
// BulkUsersRequest object:
{
  users: UserPayload[]; // users: Array of users to ingest (maximum 100 users per request)
  connectionId?: string; // Optional: Connection identifier for multi-connection scenarios
}

User payload structure

The UserPayload type supports comprehensive user information:

1
2
type UserPayload = {
  externalId: string;           // Required: Unique external identifier for the user
  nickname?: string;            // Optional: User's nickname
  displayName?: string;         // Optional: Display name for the user
  photos?: UserPhoto[];         // Optional: User profile photos
  emails?: UserEmail[];         // Optional: User email addresses
  extendedProfile?: UserExtendedProfile; // Optional: Additional profile information
  updateSequenceNumber?: number; // Optional: Sequence number for tracking updates
};

Supporting types

1
2

type UserPhoto = {
  value: string;         // URL or data URI of the photo
  type: string;          // Type of photo (e.g., 'photo')
};

type UserEmail = {
  value: string;         // Email address
  primary: boolean;      // Whether this is the primary email
};

type UserExtendedProfile = {
  jobTitle?: string;           // User's job title
  department?: string;         // User's department
  organization?: string;       // User's organization
  location?: string;           // User's location
  phoneNumbers?: UserPhoneNumber[]; // User's phone numbers
};

type UserPhoneNumber = {
  type?: string;         // Type of phone number (e.g., 'mobile', 'work')
  value: string;         // Phone number
};

Usage examples

Basic user creation

1
2
import { graph } from '@forge/teamwork-graph';
const user = {
  externalId: 'user-123',
  displayName: 'Test User',
  nickname: 'tester',
  photos: [
    {
      value: 'https://example.com/avatar.jpg',
      type: 'photo'
    }
  ],
  emails: [
    { value: 'test@example.com', primary: true },
    { value: 'backup@example.com', primary: false }
  ],
  extendedProfile: {
    jobTitle: 'Software Engineer',
    department: 'Engineering',
    organization: 'Tech Corp',
    location: 'San Francisco'
  }
};
const request = {
  users: [user],
  connectionId: 'connection-id-123'
};
const response = await graph.setUsers(request);

Bulk user creation

1
2
const users = [
  {
    externalId: 'user-1',
    displayName: 'John Doe',
    emails: [{ value: 'john@example.com', primary: true }]
  },
  {
    externalId: 'user-2',
    displayName: 'Jane Smith',
    emails: [{ value: 'jane@example.com', primary: true }]
  }
];
const response = await graph.setUsers({
  users,
  connectionId: 'connection-id-123'
});

Minimal user creation

1
2
const minimalUser = {
  externalId: 'user-123',
  displayName: 'Simple User'
};
const response = await graph.setUsers({
  users: [minimalUser]
});

Request limits

  • Maximum users per request: 100
  • Minimum users per request: 1

Request validation

The method validates the following:

  • Must be an array: The users field must be a valid array.
  • Cannot be empty: The users array cannot be empty.
  • Maximum limit: Cannot exceed 100 users per request.

Error handling

Error messageDescription
users must be an arrayThe users field is not an array.
users array cannot be emptyThe users array is empty
Bulk user ingestion supports maximum 100 users. Received XThe number of users per request has exceeded the maximum limit.

Response

The method returns a promise that resolves to a BulkUsersResponse object.

1
2
// BulkUsersResponse
{
  success: boolean;           // Indicates if the overall operation was successful
  results?: {
    success: Array<{         // Array of users successfully ingested
      externalId: string;    // The external ID that was processed
      statusCode: number;    // 200-299
    }>;
    failures: Array<{        // Array of users not ingested
      externalId: string;    // The external ID that was processed
      statusCode: number;    // non 200-299
      error: string;         // Error message for this specific user
    }>;
  };
  error?: string;            // Overall error message (if operation failed)
  originalError?: unknown;   // Original error object (if available)
}

Type safety

The SDK provides type-safe request and response objects that ensure compile-time validation:

1
2
import { types } from '@forge/teamwork-graph';

// Type-safe user creation
const user: types.UserPayload = {
  externalId: 'user-123',
  displayName: 'Test User',
  emails: [{ value: 'test@example.com', primary: true }]
};

// Type-safe request creation
const request: types.BulkUsersRequest = {
  users: [user],
  connectionId: 'connection-id-123'
};

// Type-safe response handling
const response = await graph.setUsers(request);
if (response.success && response.results) {
  // TypeScript knows results exists here and provides proper typing
  response.results.success.forEach(result => {
    // result is properly typed with externalId, success, and statusCode properties
    console.log(`Successfully created user: ${result.externalId}`);
  });
  response.results.failures.forEach(result => {
    // result is properly typed with error information
    console.error(`Failed to create user: ${result.externalId}, Error: ${result.error}`);
  });
}

The type system ensures:

  • user object has correct UserPayload structure with proper email and name types
  • request.users must be an array of UserPayload objects
  • response.results has properly typed success and failures arrays
  • Compile-time validation prevents type mismatches

Rate this page: