Module: Auth0::Api::V2::Jobs

Included in:
Auth0::Api::V2
Defined in:
lib/auth0/api/v2/jobs.rb

Overview

Methods to use the jobs endpoints

Instance Method Summary collapse

Instance Method Details

#export_users(options = {}) ⇒ json

Export all users to a file using a long running job.

Parameters:

  • options (hash) (defaults to: {})

    The options used to configure the output file. :connection_id [string] Database connection ID to export from. :format [string] The format of the file. Valid values are: “json” and “csv”. :limit [integer] Limit the number of users to export. :fields [array] A list of fields to be included in the CSV.

    This can either be an array of strings representing field names, or an object.
    If it's a string, it is mapped to the correct { name: '<field name>' } object required by the endpoint.
    If it's an object, it is passed through as-is to the endpoint.
    If omitted, a set of predefined fields will be exported.
    

Returns:

  • (json)

    Returns the job status and properties.

See Also:



69
70
71
72
73
74
75
76
77
78
# File 'lib/auth0/api/v2/jobs.rb', line 69

def export_users(options = {})
  request_params = {
    connection_id: options.fetch(:connection_id, nil),
    format: options.fetch(:format, nil),
    limit: options.fetch(:limit, nil),
    fields: fields_for_export(options.fetch(:fields, nil))
  }
  path = "#{jobs_path}/users-exports"
  post(path, request_params)
end

#get_job(job_id) ⇒ json

Retrieves a job. Useful to check its status.

Parameters:

  • job_id (string)

    The ID of the job.

Returns:

  • (json)

    Returns the job status and properties.

Raises:

See Also:



11
12
13
14
15
16
# File 'lib/auth0/api/v2/jobs.rb', line 11

def get_job(job_id)
  raise Auth0::InvalidParameter, 'Must specify a job id' if job_id.to_s.empty?

  path = "#{jobs_path}/#{job_id}"
  get(path)
end

#get_job_errors(job_id) ⇒ json

Retrieve error details based on the id of the job. Useful to check its status.

Parameters:

  • job_id (string)

    The ID of the job.

Returns:

  • (json)

    Returns the job error details.

Raises:

See Also:



23
24
25
26
27
28
# File 'lib/auth0/api/v2/jobs.rb', line 23

def get_job_errors(job_id)
  raise Auth0::InvalidParameter, 'Must specify a job id' if job_id.to_s.empty?

  path = "#{jobs_path}/#{job_id}/errors"
  get(path)
end

#import_users(users_file, connection_id, options = {}) ⇒ json

Imports users to a connection from a file using a long running job. Documentation for the file format: docs.auth0.com/bulk-import

Parameters:

  • users_file (file)

    A file containing the users to import.

  • connection_id (string)

    Database connection ID to import to.

  • options (hash) (defaults to: {})
    • :upsert [boolean] Update the user if already exists. False by default.

    • :external_id [string] Customer defined id

    • :send_completion_email [boolean] If true, send the completion email to all tenant owners when the job is finished. True by default.

Returns:

  • (json)

    Returns the job status and properties.

Raises:

See Also:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/auth0/api/v2/jobs.rb', line 41

def import_users(users_file, connection_id, options = {})
  raise Auth0::InvalidParameter, 'Must specify a valid file' if users_file.to_s.empty?
  raise Auth0::InvalidParameter, 'Must specify a connection_id' if connection_id.to_s.empty?

  request_params = {
    users: users_file,
    connection_id: connection_id,
    upsert: options.fetch(:upsert, false),
    external_id: options.fetch(:external_id, nil),
    send_completion_email: options.fetch(:send_completion_email, true)
  }
  path = "#{jobs_path}/users-imports"
  post_file(path, request_params)
end

#send_verification_email(user_id, client_id = nil, identity: nil, organization_id: nil) ⇒ json

Send an email to the specified user that asks them to click a link to verify their email address.

Parameters:

  • user_id (string)

    The user_id of the user to whom the email will be sent.

  • client_id (string) (defaults to: nil)

    Client ID to send an Application-specific email.

  • identity (hash) (defaults to: nil)

    Used to verify secondary, federated, and passwordless-email identities.

    • :user_id [string] user_id of the identity.

    • :provider [string] provider of the identity.

  • organization_id (string) (defaults to: nil)

    organization id

Returns:

  • (json)

    Returns the job status and properties.

Raises:

See Also:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/auth0/api/v2/jobs.rb', line 90

def send_verification_email(user_id, client_id = nil, identity: nil, organization_id: nil)
  raise Auth0::InvalidParameter, 'Must specify a user id' if user_id.to_s.empty?

  request_params = { user_id: user_id }
  request_params[:client_id] = client_id unless client_id.nil?
  request_params[:organization_id] = organization_id unless organization_id.nil?

  if identity
    unless identity.is_a? Hash
      raise Auth0::InvalidParameter, 'Identity must be a hash send an email verification'
    end
    request_params[:identity] = identity
  end

  path = "#{jobs_path}/verification-email"
  post(path, request_params)
end