Class: WorkOS::ClientApi

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ClientApi

Returns a new instance of ClientApi.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create_token(organization_id:, user_id:, request_options: {}) ⇒ WorkOS::ClientApiTokenResponse

Generate a Client API token

Parameters:

  • organization_id (String)

    The ID of the organization to scope the Client API token to.

  • user_id (String)

    The ID of the user to issue the Client API token for.

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

    (see WorkOS::Types::RequestOptions)

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/workos/client_api.rb', line 18

def create_token(
  organization_id:,
  user_id:,
  request_options: {}
)
  body = {
    "organization_id" => organization_id,
    "user_id" => user_id
  }
  response = @client.request(
    method: :post,
    path: "/client/token",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::ClientApiTokenResponse.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