Class: WorkOS::Organizations

Inherits:
Object
  • Object
show all
Defined in:
lib/workos/organizations.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Organizations

Returns a new instance of Organizations.



9
10
11
# File 'lib/workos/organizations.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#create_it_contact(organization_id:, email:, request_options: {}) ⇒ WorkOS::ItContact

Create an IT contact

Parameters:

  • organization_id (String)

    The ID of the organization.

  • email (String)

    The email address of the IT contact.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/workos/organizations.rb', line 293

def create_it_contact(
  organization_id:,
  email:,
  request_options: {}
)
  body = {
    "email" => email
  }
  response = @client.request(
    method: :post,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/it_contacts",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ItContact.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#create_organization(name:, allow_profiles_outside_organization: nil, domains: nil, domain_data: nil, metadata: WorkOS::OMIT, external_id: WorkOS::OMIT, request_options: {}) ⇒ WorkOS::Organization

Create an Organization

Parameters:

  • name (String)

    The name of the organization.

  • allow_profiles_outside_organization (Boolean, nil) (defaults to: nil)

    Whether the organization allows profiles from outside the organization to sign in.

  • domains (Array<String>, nil) (defaults to: nil)

    (deprecated) The domains associated with the organization. Deprecated in favor of domain_data.

  • domain_data (Array<WorkOS::OrganizationDomainData>, nil) (defaults to: nil)

    The domains associated with the organization, including verification state.

  • metadata (Hash{String => String}, nil) (defaults to: WorkOS::OMIT)

    Object containing metadata key/value pairs associated with the Organization.

  • external_id (String, nil) (defaults to: WorkOS::OMIT)

    An external identifier for the Organization.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



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
# File 'lib/workos/organizations.rb', line 74

def create_organization(
  name:,
  allow_profiles_outside_organization: nil,
  domains: nil,
  domain_data: nil,
  metadata: WorkOS::OMIT,
  external_id: WorkOS::OMIT,
  request_options: {}
)
  body = {
    "name" => name,
    "allow_profiles_outside_organization" => allow_profiles_outside_organization,
    "domains" => domains,
    "domain_data" => domain_data
  }.compact
  body["metadata"] =  unless .equal?(WorkOS::OMIT)
  body["external_id"] = external_id unless external_id.equal?(WorkOS::OMIT)
  response = @client.request(
    method: :post,
    path: "/organizations",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Organization.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#delete_it_contact(organization_id:, contact_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an IT contact

Parameters:

  • organization_id (String)

    The ID of the organization.

  • contact_id (String)

    The ID of the IT contact.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/workos/organizations.rb', line 318

def delete_it_contact(
  organization_id:,
  contact_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/it_contacts/#{WorkOS::Util.encode_path(contact_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_organization(id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete an Organization

Parameters:

  • id (String)

    Unique identifier of the Organization.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/workos/organizations.rb', line 188

def delete_organization(
  id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/organizations/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#get_audit_log_configuration(id:, request_options: {}) ⇒ WorkOS::AuditLogConfiguration

Get Audit Log Configuration

Parameters:

  • id (String)

    Unique identifier of the Organization.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/workos/organizations.rb', line 205

def get_audit_log_configuration(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(id)}/audit_log_configuration",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::AuditLogConfiguration.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#get_organization(id:, request_options: {}) ⇒ WorkOS::Organization

Get an Organization

Parameters:

  • id (String)

    Unique identifier of the Organization.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/workos/organizations.rb', line 126

def get_organization(
  id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Organization.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#get_organization_by_external_id(external_id:, request_options: {}) ⇒ WorkOS::Organization

Get an Organization by External ID

Parameters:

  • external_id (String)

    The external ID of the Organization.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/workos/organizations.rb', line 107

def get_organization_by_external_id(
  external_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/organizations/external_id/#{WorkOS::Util.encode_path(external_id)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::Organization.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#invite_it_contact(organization_id:, contact_id:, intents:, request_options: {}) ⇒ void

This method returns an undefined value.

Invite an IT contact

Parameters:

  • organization_id (String)

    The ID of the organization.

  • contact_id (String)

    The ID of the IT contact.

  • intents (Array<WorkOS::Types::InviteItContactIntents>)

    The Admin Portal features that the IT contact can configure.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/workos/organizations.rb', line 338

def invite_it_contact(
  organization_id:,
  contact_id:,
  intents:,
  request_options: {}
)
  body = {
    "intents" => intents
  }
  @client.request(
    method: :post,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/it_contacts/#{WorkOS::Util.encode_path(contact_id)}/invite",
    auth: true,
    body: body,
    request_options: request_options
  )
  nil
end

#list_authorized_applications(organization_id:, before: nil, after: nil, limit: 10, order: "desc", request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::OrganizationAuthorizedConnectApplicationListData>

List authorized applications

Parameters:

  • organization_id (String)

    The ID of the organization.

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with "obj_123", your subsequent call can include before="obj_123" to fetch a new batch of objects before "obj_123".

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with "obj_123", your subsequent call can include after="obj_123" to fetch a new batch of objects after "obj_123".

  • limit (Integer, nil) (defaults to: 10)

    Upper limit on the number of objects to return, between 1 and 100.

  • order (WorkOS::Types::PaginationOrder, nil) (defaults to: "desc")

    Order the results by the creation time. Supported values are "asc" (ascending), "desc" (descending), and "normal" (descending with reversed cursor semantics where before fetches older records and after fetches newer records).

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/workos/organizations.rb', line 228

def list_authorized_applications(
  organization_id:,
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order
  }.compact
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/authorized_applications",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_authorized_applications(
      organization_id: organization_id,
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::OrganizationAuthorizedConnectApplicationListData,
    filters: {organization_id: organization_id, before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_it_contacts(organization_id:, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::ItContact>

List IT contacts

Parameters:

  • organization_id (String)

    The ID of the organization.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/workos/organizations.rb', line 271

def list_it_contacts(
  organization_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/it_contacts",
    auth: true,
    request_options: request_options
  )
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::ItContact,
    filters: {organization_id: organization_id}
  )
end

#list_organizations(before: nil, after: nil, limit: 10, order: "desc", domains: nil, search: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::Organization>

List Organizations

Parameters:

  • before (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with "obj_123", your subsequent call can include before="obj_123" to fetch a new batch of objects before "obj_123".

  • after (String, nil) (defaults to: nil)

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with "obj_123", your subsequent call can include after="obj_123" to fetch a new batch of objects after "obj_123".

  • limit (Integer, nil) (defaults to: 10)

    Upper limit on the number of objects to return, between 1 and 100.

  • order (WorkOS::Types::PaginationOrder, nil) (defaults to: "desc")

    Order the results by the creation time. Supported values are "asc" (ascending), "desc" (descending), and "normal" (descending with reversed cursor semantics where before fetches older records and after fetches newer records).

  • domains (Array<String>, nil) (defaults to: nil)

    The domains of an Organization. Any Organization with a matching domain will be returned.

  • search (String, nil) (defaults to: nil)

    Searchable text for an Organization. Matches against the organization name.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



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
# File 'lib/workos/organizations.rb', line 22

def list_organizations(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  domains: nil,
  search: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "domains" => domains,
    "search" => search
  }.compact
  response = @client.request(
    method: :get,
    path: "/organizations",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_organizations(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      domains: domains,
      search: search,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::Organization,
    filters: {before: before, limit: limit, order: order, domains: domains, search: search},
    fetch_next: fetch_next
  )
end

#revoke_it_contact(organization_id:, contact_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Revoke an IT contact's invitation

Parameters:

  • organization_id (String)

    The ID of the organization.

  • contact_id (String)

    The ID of the IT contact.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/workos/organizations.rb', line 362

def revoke_it_contact(
  organization_id:,
  contact_id:,
  request_options: {}
)
  @client.request(
    method: :post,
    path: "/organizations/#{WorkOS::Util.encode_path(organization_id)}/it_contacts/#{WorkOS::Util.encode_path(contact_id)}/revoke",
    auth: true,
    request_options: request_options
  )
  nil
end

#update_organization(id:, name: nil, allow_profiles_outside_organization: nil, domains: nil, domain_data: nil, stripe_customer_id: nil, metadata: WorkOS::OMIT, external_id: WorkOS::OMIT, request_options: {}) ⇒ WorkOS::Organization

Update an Organization

Parameters:

  • id (String)

    Unique identifier of the Organization.

  • name (String, nil) (defaults to: nil)

    The name of the organization.

  • allow_profiles_outside_organization (Boolean, nil) (defaults to: nil)

    Whether the organization allows profiles from outside the organization to sign in.

  • domains (Array<String>, nil) (defaults to: nil)

    (deprecated) The domains associated with the organization. Deprecated in favor of domain_data.

  • domain_data (Array<WorkOS::OrganizationDomainData>, nil) (defaults to: nil)

    The domains associated with the organization, including verification state.

  • stripe_customer_id (String, nil) (defaults to: nil)

    The Stripe customer ID associated with the organization.

  • metadata (Hash{String => String}, nil) (defaults to: WorkOS::OMIT)

    Object containing metadata key/value pairs associated with the Organization.

  • external_id (String, nil) (defaults to: WorkOS::OMIT)

    An external identifier for the Organization.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/workos/organizations.rb', line 152

def update_organization(
  id:,
  name: nil,
  allow_profiles_outside_organization: nil,
  domains: nil,
  domain_data: nil,
  stripe_customer_id: nil,
  metadata: WorkOS::OMIT,
  external_id: WorkOS::OMIT,
  request_options: {}
)
  body = {
    "name" => name,
    "allow_profiles_outside_organization" => allow_profiles_outside_organization,
    "domains" => domains,
    "domain_data" => domain_data,
    "stripe_customer_id" => stripe_customer_id
  }.compact
  body["metadata"] =  unless .equal?(WorkOS::OMIT)
  body["external_id"] = external_id unless external_id.equal?(WorkOS::OMIT)
  response = @client.request(
    method: :put,
    path: "/organizations/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::Organization.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end