Class: Attio::Resources::Deals Private

Inherits:
Base
  • Object
show all
Defined in:
lib/attio/resources/deals.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Deals resource for managing sales opportunities

Examples:

List all deals

client.deals.list

Create a new deal

client.deals.create(
  data: {
    name: "Enterprise Contract",
    value: 50000,
    stage_id: "stage_123",
    company_id: "company_456"
  }
)

Update deal stage

client.deals.update_stage(id: "deal_123", stage_id: "stage_won")

Since:

  • 1.0.0

API:

  • private

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Attio::Resources::Base

Instance Method Details

#create(data:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new deal

Parameters:

  • The deal data

Options Hash (data:):

  • :name (String)

    The deal name (required)

  • :value (Float)

    The deal value

  • :stage_id (String)

    The stage ID

  • :company_id (String)

    Associated company ID

  • :owner_id (String)

    The owner user ID

  • :close_date (Date)

    Expected close date

  • :currency (String)

    Currency code (USD, EUR, etc.)

  • :probability (Float)

    Win probability (0-100)

Returns:

  • The created deal

Since:

  • 1.0.0

API:

  • private



56
57
58
59
60
61
# File 'lib/attio/resources/deals.rb', line 56

def create(data:)
  validate_required_hash!(data, "Data")
  validate_required_string!(data[:name], "Deal name")

  request(:post, "objects/deals/records", { data: data })
end

#delete(id:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Delete a deal

Parameters:

  • The deal ID to delete

Returns:

  • Confirmation of deletion

Since:

  • 1.0.0

API:

  • private



79
80
81
82
# File 'lib/attio/resources/deals.rb', line 79

def delete(id:)
  validate_id!(id, "Deal")
  request(:delete, "objects/deals/records/#{id}")
end

#get(id:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get a specific deal

Parameters:

  • The deal ID

Returns:

  • The deal data

Since:

  • 1.0.0

API:

  • private



39
40
41
42
# File 'lib/attio/resources/deals.rb', line 39

def get(id:)
  validate_id!(id, "Deal")
  request(:get, "objects/deals/records/#{id}")
end

#list(params = {}) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

List all deals

Parameters:

  • (defaults to: {})

    Optional query parameters

Options Hash (params):

  • :filter (Hash)

    Filter conditions

  • :sorts (Array<Hash>)

    Sort criteria

  • :limit (Integer)

    Maximum number of results

  • :offset (String)

    Pagination offset

Returns:

  • The API response

Since:

  • 1.0.0

API:

  • private



31
32
33
# File 'lib/attio/resources/deals.rb', line 31

def list(params = {})
  request(:get, "objects/deals/records", params)
end

#list_by_company(company_id:, params: {}) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

List deals by company

Parameters:

  • The company ID to filter by

  • (defaults to: {})

    Additional query parameters

Returns:

  • Deals for the specified company

Since:

  • 1.0.0

API:

  • private



146
147
148
149
150
151
152
# File 'lib/attio/resources/deals.rb', line 146

def list_by_company(company_id:, params: {})
  validate_required_string!(company_id, "Company")

  filter = { company_id: { "$eq" => company_id } }
  merged_params = params.merge(filter: filter)
  list(merged_params)
end

#list_by_owner(owner_id:, params: {}) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

List deals by owner

Parameters:

  • The owner user ID to filter by

  • (defaults to: {})

    Additional query parameters

Returns:

  • Deals owned by the specified user

Since:

  • 1.0.0

API:

  • private



159
160
161
162
163
164
165
# File 'lib/attio/resources/deals.rb', line 159

def list_by_owner(owner_id:, params: {})
  validate_required_string!(owner_id, "Owner")

  filter = { owner_id: { "$eq" => owner_id } }
  merged_params = params.merge(filter: filter)
  list(merged_params)
end

#list_by_stage(stage_id:, params: {}) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

List deals by stage

Parameters:

  • The stage ID to filter by

  • (defaults to: {})

    Additional query parameters

Returns:

  • Deals in the specified stage

Since:

  • 1.0.0

API:

  • private



133
134
135
136
137
138
139
# File 'lib/attio/resources/deals.rb', line 133

def list_by_stage(stage_id:, params: {})
  validate_required_string!(stage_id, "Stage")

  filter = { stage_id: { "$eq" => stage_id } }
  merged_params = params.merge(filter: filter)
  list(merged_params)
end

#mark_lost(id:, lost_reason: nil, lost_date: nil) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Mark a deal as lost

Parameters:

  • The deal ID

  • (defaults to: nil)

    The reason for losing the deal

  • (defaults to: nil)

    The date the deal was lost (defaults to today)

Returns:

  • The updated deal

Since:

  • 1.0.0

API:

  • private



118
119
120
121
122
123
124
125
126
# File 'lib/attio/resources/deals.rb', line 118

def mark_lost(id:, lost_reason: nil, lost_date: nil)
  validate_id!(id, "Deal")

  data = { status: "lost" }
  data[:lost_reason] = lost_reason if lost_reason
  data[:lost_date] = lost_date if lost_date

  update(id: id, data: data)
end

#mark_won(id:, won_date: nil, actual_value: nil) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Mark a deal as won

Parameters:

  • The deal ID

  • (defaults to: nil)

    The date the deal was won (defaults to today)

  • (defaults to: nil)

    The actual value (optional, defaults to deal value)

Returns:

  • The updated deal

Since:

  • 1.0.0

API:

  • private



102
103
104
105
106
107
108
109
110
# File 'lib/attio/resources/deals.rb', line 102

def mark_won(id:, won_date: nil, actual_value: nil)
  validate_id!(id, "Deal")

  data = { status: "won" }
  data[:won_date] = won_date if won_date
  data[:actual_value] = actual_value if actual_value

  update(id: id, data: data)
end

#pipeline_value(stage_id: nil, owner_id: nil) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Calculate pipeline value

Parameters:

  • (defaults to: nil)

    Optional stage ID to filter by

  • (defaults to: nil)

    Optional owner ID to filter by

Returns:

  • Pipeline statistics including total value, count, and average

Since:

  • 1.0.0

API:

  • private



172
173
174
175
176
177
178
179
180
# File 'lib/attio/resources/deals.rb', line 172

def pipeline_value(stage_id: nil, owner_id: nil)
  params = { filter: {} }
  params[:filter][:stage_id] = { "$eq" => stage_id } if stage_id
  params[:filter][:owner_id] = { "$eq" => owner_id } if owner_id

  # This would typically be a specialized endpoint, but we'll use list
  # and let the client calculate the statistics
  list(params)
end

#update(id:, data:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update a deal

Parameters:

  • The deal ID to update

  • The data to update

Returns:

  • The updated deal

Since:

  • 1.0.0

API:

  • private



68
69
70
71
72
73
# File 'lib/attio/resources/deals.rb', line 68

def update(id:, data:)
  validate_id!(id, "Deal")
  validate_required_hash!(data, "Data")

  request(:patch, "objects/deals/records/#{id}", { data: data })
end

#update_stage(id:, stage_id:) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update a deal's stage

Parameters:

  • The deal ID

  • The new stage ID

Returns:

  • The updated deal

Since:

  • 1.0.0

API:

  • private



89
90
91
92
93
94
# File 'lib/attio/resources/deals.rb', line 89

def update_stage(id:, stage_id:)
  validate_id!(id, "Deal")
  validate_required_string!(stage_id, "Stage")

  update(id: id, data: { stage_id: stage_id })
end