Class: WorkOS::Pipes

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Pipes

Returns a new instance of Pipes.



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

def initialize(client)
  @client = client
end

Instance Method Details

#authorize_data_integration(slug:, user_id:, organization_id: nil, return_to: nil, config: nil, request_options: {}) ⇒ WorkOS::DataIntegrationAuthorizeUrlResponse

Get authorization URL

Parameters:

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

  • user_id (String)

    The ID of the user to authorize.

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

    An organization ID to scope the authorization to a specific organization.

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

    The URL to redirect the user to after authorization.

  • config (Hash{String => String}, nil) (defaults to: nil)

    Connect-time config values for the provider-declared installation-scope fields (e.g. a Zendesk subdomain), keyed by the config field. Only fields the provider declares may be supplied, and required fields must be provided unless already pinned on the integration.

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

    (see WorkOS::Types::RequestOptions)

Returns:



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/workos/pipes.rb', line 219

def authorize_data_integration(
  slug:,
  user_id:,
  organization_id: nil,
  return_to: nil,
  config: nil,
  request_options: {}
)
  body = {
    "user_id" => user_id,
    "organization_id" => organization_id,
    "return_to" => return_to,
    "config" => config
  }.compact
  response = @client.request(
    method: :post,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}/authorize",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegrationAuthorizeUrlResponse.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_data_integration(provider:, description: WorkOS::OMIT, enabled: nil, scopes: WorkOS::OMIT, auth_methods: nil, config: nil, credentials: nil, api_key: nil, custom_provider: nil, request_options: {}) ⇒ WorkOS::DataIntegration

Create a data integration

Parameters:

  • provider (String)

    The provider to create a Data Integration for. For a built-in provider use its slug (e.g. github, slack). For a custom provider, this is the new provider slug and custom_provider must be supplied. A custom provider slug cannot shadow an existing global provider slug.

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

    An optional description of the Data Integration.

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

    Whether the Data Integration is enabled. Defaults to false.

  • scopes (Array<String>, nil) (defaults to: WorkOS::OMIT)

    The OAuth scopes to request for the Data Integration. Defaults to the provider's configured scopes when omitted.

  • auth_methods (Array<WorkOS::Types::CreateDataIntegrationAuthMethods>, nil) (defaults to: nil)

    How accounts authenticate with the provider. Defaults to ["oauth"]. Use ["api_key"] to declare an API key integration; credentials is then not required and keys are supplied per-tenant (optionally via api_key on this request).

  • config (Hash{String => String}, nil) (defaults to: nil)

    Provider-specific config values (e.g. a Snowflake account_identifier), keyed by the config field. Only fields the built-in provider declares are accepted.

  • credentials (WorkOS::DataIntegrationCredentialsInput, nil) (defaults to: nil)

    The OAuth credentials to configure for the Data Integration. Required for OAuth integrations; omit when auth_methods is ["api_key"].

  • api_key (WorkOS::ApiKeyInstallation, nil) (defaults to: nil)

    An optional API key to install for the first tenant on an api_key integration. Omit to declare a keyless integration; tenants can be added later via the per-installation API key path.

  • custom_provider (WorkOS::CustomProviderDefinition, nil) (defaults to: nil)

    The OAuth definition for a custom provider. Supply this to define a custom provider; omit it to create an integration for a built-in provider.

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

    (see WorkOS::Types::RequestOptions)

Returns:



69
70
71
72
73
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
102
# File 'lib/workos/pipes.rb', line 69

def create_data_integration(
  provider:,
  description: WorkOS::OMIT,
  enabled: nil,
  scopes: WorkOS::OMIT,
  auth_methods: nil,
  config: nil,
  credentials: nil,
  api_key: nil,
  custom_provider: nil,
  request_options: {}
)
  body = {
    "provider" => provider,
    "enabled" => enabled,
    "auth_methods" => auth_methods,
    "config" => config,
    "credentials" => credentials,
    "api_key" => api_key,
    "custom_provider" => custom_provider
  }.compact
  body["description"] = description unless description.equal?(WorkOS::OMIT)
  body["scopes"] = scopes unless scopes.equal?(WorkOS::OMIT)
  response = @client.request(
    method: :post,
    path: "/data-integrations",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegration.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_data_integration_credential(slug:, user_id:, organization_id: nil, request_options: {}) ⇒ WorkOS::DataIntegrationCredentialsResponse

Vend credentials for a connected account

Parameters:

  • slug (String)

    The identifier of the integration.

  • user_id (String)

    A User identifier.

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

    An Organization identifier. Optional parameter to scope the connection to a specific organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/workos/pipes.rb', line 251

def create_data_integration_credential(
  slug:,
  user_id:,
  organization_id: nil,
  request_options: {}
)
  body = {
    "user_id" => user_id,
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :post,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}/credentials",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegrationCredentialsResponse.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_user_connected_account(user_id:, slug:, access_token: nil, refresh_token: nil, expires_at: nil, scopes: nil, state: nil, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectedAccount

Import a connected account

Parameters:

  • user_id (String)

    A User identifier.

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

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

    The OAuth access token for the connected account.

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

    The OAuth refresh token for the connected account.

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

    The ISO-8601 timestamp when the access token expires. Required when access_token is provided for tokens that expire.

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

    The OAuth scopes granted for this connection.

  • state (WorkOS::Types::ConnectedAccountInputState, nil) (defaults to: nil)

    Explicitly set the state of the connected account. When omitted, the state is derived from the token combination provided.

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

    An Organization identifier. Optional parameter if the connection is scoped to an organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/workos/pipes.rb', line 339

def (
  user_id:,
  slug:,
  access_token: nil,
  refresh_token: nil,
  expires_at: nil,
  scopes: nil,
  state: nil,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  body = {
    "access_token" => access_token,
    "refresh_token" => refresh_token,
    "expires_at" => expires_at,
    "scopes" => scopes,
    "state" => state
  }.compact
  response = @client.request(
    method: :post,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/connected_accounts/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ConnectedAccount.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_data_integration(slug:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a data integration

Parameters:

  • slug (String)

    The slug identifier of the data integration.

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

    (see WorkOS::Types::RequestOptions)



167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/workos/pipes.rb', line 167

def delete_data_integration(
  slug:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#delete_user_connected_account(user_id:, slug:, organization_id: nil, request_options: {}) ⇒ void

This method returns an undefined value.

Delete a connected account

Parameters:

  • user_id (String)

    A User identifier.

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

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

    An Organization identifier. Optional parameter if the connection is scoped to an organization.

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

    (see WorkOS::Types::RequestOptions)



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/workos/pipes.rb', line 424

def (
  user_id:,
  slug:,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  @client.request(
    method: :delete,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/connected_accounts/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  nil
end

#get_access_token(provider:, user_id:, organization_id: WorkOS::OMIT, request_options: {}) ⇒ WorkOS::DataIntegrationAccessTokenResponse

Get an access token for a connected account

Parameters:

  • provider (String)

    The identifier of the integration.

  • user_id (String)

    A User identifier.

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

    An Organization identifier. Optional parameter to scope the connection to a specific organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/workos/pipes.rb', line 279

def get_access_token(
  provider:,
  user_id:,
  organization_id: WorkOS::OMIT,
  request_options: {}
)
  body = {
    "user_id" => user_id
  }
  body["organization_id"] = organization_id unless organization_id.equal?(WorkOS::OMIT)
  response = @client.request(
    method: :post,
    path: "/data-integrations/#{WorkOS::Util.encode_path(provider)}/token",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegrationAccessTokenResponse.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_data_integration(slug:, request_options: {}) ⇒ WorkOS::DataIntegration

Get a data integration

Parameters:

  • slug (String)

    The slug identifier of the data integration.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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

def get_data_integration(
  slug:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    request_options: request_options
  )
  result = WorkOS::DataIntegration.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_user_connected_account(user_id:, slug:, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectedAccount

Get a connected account

Parameters:

  • user_id (String)

    A User identifier.

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

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

    An Organization identifier. Optional parameter if the connection is scoped to an organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/workos/pipes.rb', line 307

def (
  user_id:,
  slug:,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :get,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/connected_accounts/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  result = WorkOS::ConnectedAccount.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

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

List data integrations

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).

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

    (see WorkOS::Types::RequestOptions)

Returns:



20
21
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
# File 'lib/workos/pipes.rb', line 20

def list_data_integrations(
  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: "/data-integrations",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_data_integrations(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::DataIntegration,
    filters: {before: before, limit: limit, order: order},
    fetch_next: fetch_next
  )
end

#list_user_data_providers(user_id:, organization_id: nil, request_options: {}) ⇒ WorkOS::DataIntegrationsListResponse

List providers for a user

Parameters:

  • user_id (String)

    A User identifier to list providers and connected accounts for.

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

    An Organization identifier. Optional parameter to filter connections for a specific organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/workos/pipes.rb', line 448

def list_user_data_providers(
  user_id:,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :get,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/data_providers",
    auth: true,
    params: params,
    request_options: request_options
  )
  result = WorkOS::DataIntegrationsListResponse.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

#update_data_integration(slug:, description: WorkOS::OMIT, enabled: nil, scopes: WorkOS::OMIT, credentials: nil, api_key: nil, custom_provider: nil, request_options: {}) ⇒ WorkOS::DataIntegration

Update a data integration

Parameters:

  • slug (String)

    The slug identifier of the data integration.

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

    An optional description of the Data Integration.

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

    Whether the Data Integration is enabled.

  • scopes (Array<String>, nil) (defaults to: WorkOS::OMIT)

    The OAuth scopes to request for the Data Integration. Pass null to reset to the provider's configured scopes.

  • credentials (WorkOS::DataIntegrationCredentialsInput, nil) (defaults to: nil)

    New OAuth credentials for the Data Integration. When provided, rotates the stored client secret. Mutually exclusive with api_key.

  • api_key (WorkOS::ApiKeyInstallation, nil) (defaults to: nil)

    An API key to install or rotate for a tenant on an api_key integration. Upserts the tenant installation identified by user_id (and optional organization_id).

  • custom_provider (WorkOS::UpdateCustomProviderDefinition, nil) (defaults to: nil)

    Updates to a custom provider's OAuth definition. Only valid for custom-provider integrations.

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

    (see WorkOS::Types::RequestOptions)

Returns:



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/workos/pipes.rb', line 133

def update_data_integration(
  slug:,
  description: WorkOS::OMIT,
  enabled: nil,
  scopes: WorkOS::OMIT,
  credentials: nil,
  api_key: nil,
  custom_provider: nil,
  request_options: {}
)
  body = {
    "enabled" => enabled,
    "credentials" => credentials,
    "api_key" => api_key,
    "custom_provider" => custom_provider
  }.compact
  body["description"] = description unless description.equal?(WorkOS::OMIT)
  body["scopes"] = scopes unless scopes.equal?(WorkOS::OMIT)
  response = @client.request(
    method: :put,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::DataIntegration.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

#update_data_integration_api_key(slug:, user_id:, secret:, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectedAccount

Upsert an API key for a connected account

Parameters:

  • slug (String)

    The identifier of the integration.

  • user_id (String)

    A User identifier.

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

    An Organization identifier. Optional parameter to scope the connection to a specific organization.

  • secret (String)

    The API key secret to store for this integration.

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

    (see WorkOS::Types::RequestOptions)

Returns:



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/workos/pipes.rb', line 187

def update_data_integration_api_key(
  slug:,
  user_id:,
  secret:,
  organization_id: nil,
  request_options: {}
)
  body = {
    "user_id" => user_id,
    "organization_id" => organization_id,
    "secret" => secret
  }.compact
  response = @client.request(
    method: :put,
    path: "/data-integrations/#{WorkOS::Util.encode_path(slug)}/api-key",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ConnectedAccount.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

#update_user_connected_account(user_id:, slug:, access_token: nil, refresh_token: nil, expires_at: nil, scopes: nil, state: nil, organization_id: nil, request_options: {}) ⇒ WorkOS::ConnectedAccount

Update a connected account

Parameters:

  • user_id (String)

    A User identifier.

  • slug (String)

    The slug identifier of the provider (e.g., github, slack, notion).

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

    The OAuth access token for the connected account.

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

    The OAuth refresh token for the connected account.

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

    The ISO-8601 timestamp when the access token expires. Required when access_token is provided for tokens that expire.

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

    The OAuth scopes granted for this connection.

  • state (WorkOS::Types::ConnectedAccountInputState, nil) (defaults to: nil)

    Explicitly set the state of the connected account. When omitted, the state is derived from the token combination provided.

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

    An Organization identifier. Optional parameter if the connection is scoped to an organization.

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

    (see WorkOS::Types::RequestOptions)

Returns:



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/workos/pipes.rb', line 384

def (
  user_id:,
  slug:,
  access_token: nil,
  refresh_token: nil,
  expires_at: nil,
  scopes: nil,
  state: nil,
  organization_id: nil,
  request_options: {}
)
  params = {
    "organization_id" => organization_id
  }.compact
  body = {
    "access_token" => access_token,
    "refresh_token" => refresh_token,
    "expires_at" => expires_at,
    "scopes" => scopes,
    "state" => state
  }.compact
  response = @client.request(
    method: :put,
    path: "/user_management/users/#{WorkOS::Util.encode_path(user_id)}/connected_accounts/#{WorkOS::Util.encode_path(slug)}",
    auth: true,
    params: params,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ConnectedAccount.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