> For a complete page index, fetch https://developer.close.com/llms.txt

# Create an opportunity

POST https://api.close.com/api/v1/opportunity/
Content-Type: application/json

Create an opportunity, optionally linked to an existing lead.

**custom.FIELD\_ID** (optional): Set custom fields by setting `custom.FIELD_ID` to the field value, where FIELD\_ID is the ID of the custom field, e.g.:

```json
{ "custom.cf_v6S011I6MqcbVvB2FA5Nk8dr5MkL8sWuCiG8cUleO9c": "value", "custom.cf_8wtBWsdRU2Fur7GDnEeXQ7ra2Vu7R4hG1SNYdiEhh0F": "other value" }
```

If a custom field has `accepts_multiple_values: true`, the entire value will be replaced. For example, given an Opportunity has a Custom Choice Field with value `["A", "B"]`, adding choice `"C"` would mean setting the value to `["A", "B", "C"]`.

Note that using the `custom` field dict or the `custom.FIELD_NAME` syntax (instead of custom field IDs) is deprecated and will be removed from the API. See [Custom Fields](https://developer.close.com/api/resources/custom-fields) for more details.

Reference: https://developer.close.com/api/resources/opportunities/create

## Authentication

- `Authorization` header (basic auth, required) — Use your API key as the username and leave the password empty.
- `Authorization` header (bearer token, required)

## Request

### Body (application/json)

- `attachments` (list of object, optional, nullable)
  - `filename` (string, required)
  - `url` (string, required)
  - `content_type` (string, optional, default: )
- `confidence` (integer, optional, nullable)
- `contact_id` (string, optional, nullable)
- `created_by` (string, optional, nullable)
- `date_created` (datetime, optional, nullable)
- `date_won` (datetime, optional, nullable) — If not set on the resource or in the request, `date_won` will be set automatically to today's date when setting `status_id` to a status with type `won`. The `x-tz-offset` header, used to pass your timezone's UTC offset, will be taken into account.
- `lead_id` (string, optional, nullable) — Opportunities belong to exactly one Lead. If not provided, a new lead will be created (appearing as "Untitled" in the UI).
- `note` (string, optional, nullable) — Plaintext/markdown version of the note. If `note_html` is also provided in the same request, this value is ignored and `note` is derived from the HTML instead.
- `note_html` (string, optional, nullable) — Rich-text HTML version of the note. When set, `note` is automatically populated with the plaintext version (tags become markdown), overriding any `note` value passed in the same request.
- `pipeline_id` (string, optional, nullable) — Specify which pipeline this opportunity should belong to. When supplied without `status_id`, the opportunity will be created with the first available status of that pipeline. When supplied with `status_id`, the status must belong to the specified pipeline or a 400 error will be returned. If the pipeline does not exist, a 400 error will be returned. See the [Pipelines API](https://developer.close.com/api/resources/pipelines).
- `status_id` (string, optional, nullable) — Post a `status_id` to create an opportunity with a specific status. If omitted, the organization's default (first) status will be used (or the first status of the `pipeline_id` if provided). See the [Opportunity Status API](https://developer.close.com/api/resources/opportunity-statuses).
- `user_id` (string, optional, nullable)
- `value` (integer, optional, nullable)
- `value_period` (enum, optional, nullable)
  - Allowed values: `one_time`, `monthly`, `annual`

## Response

### 200

Successful response

- `annualized_expected_value` (integer, required, nullable)
- `annualized_value` (integer, required, nullable)
- `confidence` (integer, required)
- `contact_id` (string, required, nullable)
- `created_by` (string, required, nullable)
- `date_created` (datetime, required)
- `date_lost` (datetime, required, nullable)
- `date_updated` (datetime, required)
- `date_won` (date, required, nullable)
- `expected_value` (integer, required, nullable)
- `id` (string, required)
- `lead_id` (string, required)
- `note` (string, required, nullable)
- `note_html` (string, required, nullable)
- `organization_id` (string, required)
- `status_id` (string, required)
- `updated_by` (string, required, nullable)
- `user_id` (string, required)
- `value` (integer, required, nullable)
- `value_period` (enum, required)
  - Allowed values: `one_time`, `monthly`, `annual`
- `attachments` (list of object, optional)
  - `content_type` (string, required, nullable)
  - `filename` (string, required, nullable)
  - `size` (integer, required, nullable)
  - `url` (string, required)
  - `thumbnail_url` (string, optional, nullable)
- `comment_summary` (object, optional, nullable)
  - `comment_count` (integer, required)
  - `thread_id` (string, required)
- `contact_name` (string, optional, nullable)
- `created_by_name` (string, optional, nullable)
- `integration_links` (list of object, optional)
  - `name` (string, required)
  - `url` (string, required)
- `is_stalled` (boolean, optional)
- `lead_name` (string, optional, nullable)
- `lead_primary_email` (object, optional, nullable)
  - `email` (string, required)
  - `is_unsubscribed` (boolean, required)
  - `type` (string, required)
- `lead_primary_phone` (list of object, optional, nullable)
  - `phone` (string, required)
  - `type` (string, required)
  - `country` (string, optional, nullable)
  - `outbound_sms_blocked` (boolean, optional)
  - `phone_formatted` (string, optional)
  - `tz_ids` (list of string, optional)
- `pipeline_id` (string, optional, nullable)
- `pipeline_name` (string, optional, nullable)
- `stall_status` (object, optional, nullable)
  - `communication_issue` (enum, required) — The communication issue that is causing the stalled opportunity. If there is no issue, set to NoIssue.
    - Allowed values: `no_issue`, `cant_get_in_touch`, `no_communication_attempts`
  - `next_action` (object, required) — An action item recommended to progress or resolve the stalled opportunity.
    - `action` (enum, required) — The recommended next step to progress or resolve the stalled opportunity
      - Allowed values: `mark_as_lost`, `change_status`, `follow_up`, `adjust_close_date`, `ask_someone_else_to_reach_out`, `change_communication_method`
    - `justification` (string, required) — A short justification for the recommended action in the sales pipeline. Maximum 2 sentences.
- `status_display_name` (string, optional)
- `status_label` (string, optional)
- `status_type` (enum, optional)
  - Allowed values: `won`, `lost`, `active`
- `suggested_action` (object, optional, nullable)
  - `action` (enum, required)
    - Allowed values: `change_status`, `adjust_close_date`, `follow_up_email`, `follow_up_call`, `follow_up_sms`
  - `details` (object or object or object or object or object, required, nullable)
    - OpportunityChangeStatusActionDetails
      - `status_id` (string, required)
    - OpportunityFollowUpEmailActionDetails
      - `contact_id` (string, required)
      - `message_draft` (string, required)
      - `subject_draft` (string, required)
    - OpportunityFollowUpSMSActionDetails
      - `contact_id` (string, required)
      - `message_draft` (string, required)
    - OpportunityFollowUpCallActionDetails
      - `call_plan` (string, required)
      - `contact_id` (string, required)
    - OpportunityAdjustCloseDateActionDetails
      - `close_date` (date, required)
  - `justification` (string, required)
- `updated_by_name` (string, optional, nullable)
- `user_name` (string, optional, nullable)
- `value_currency` (string, optional, nullable)
- `value_formatted` (string, optional, nullable)

## Examples

**Request**

```json
{
  "confidence": 90,
  "lead_id": "lead_IIDHIStmFcFQZZP0BRe99V1MCoXWz2PGCm6EDmR9v2O",
  "note_html": "<body><p>i hope this deal closes...</p></body>",
  "status_id": "stat_4ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk",
  "value": 500,
  "value_period": "monthly",
  "custom.cf_j0P7kHmgFTZZnYBFtyPSZ3uQw4dpW8xKcW7Krps8atj": "https://www.example.com/contract.pdf"
}
```

**Response**

```json
{
  "annualized_expected_value": 540000,
  "annualized_value": 600000,
  "confidence": 90,
  "contact_id": null,
  "created_by": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "date_created": "2013-02-20T10:11:50.520000+00:00",
  "date_lost": null,
  "date_updated": "2013-02-20T10:11:50.520000+00:00",
  "date_won": null,
  "expected_value": 45000,
  "id": "oppo_bJoqD4QX21AfA2fAGX5HmPQ1EgGoWBannvLj4khIfPH",
  "lead_id": "lead_IIDHIStmFcFQZZP0BRe99V1MCoXWz2PGCm6EDmR9v2O",
  "note": "i hope this deal closes...",
  "note_html": "<body><p>i hope this deal closes...</p></body>",
  "organization_id": "orga_RbREgmiiwcr1w2b4cOnCMQaQPSIFxMqAD2Dh243uxcH",
  "status_id": "stat_4ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk",
  "updated_by": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "user_id": "user_N6KhMpzHRCYQHdn4gRNIFNN5JExnsrprKA6ekxM63XA",
  "value": 50000,
  "value_period": "monthly",
  "lead_name": "Wayne Enterprises (Sample Lead)",
  "pipeline_id": "pipe_04fC628PVB0HjK2Qq5EqEf",
  "pipeline_name": "Sales",
  "status_label": "Active",
  "status_type": "active",
  "user_name": "Anthony Nemitz",
  "value_currency": "USD",
  "value_formatted": "$50 monthly",
  "custom.cf_j0P7kHmgFTZZnYBFtyPSZ3uQw4dpW8xKcW7Krps8atj": "https://www.example.com/contract.pdf"
}
```

**SDK Code**

```python opportunities_create_example
import requests

url = "https://api.close.com/api/v1/opportunity/"

payload = {
    "confidence": 90,
    "lead_id": "lead_IIDHIStmFcFQZZP0BRe99V1MCoXWz2PGCm6EDmR9v2O",
    "note_html": "<body><p>i hope this deal closes...</p></body>",
    "status_id": "stat_4ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk",
    "value": 500,
    "value_period": "monthly",
    "custom.cf_j0P7kHmgFTZZnYBFtyPSZ3uQw4dpW8xKcW7Krps8atj": "https://www.example.com/contract.pdf"
}
headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers, auth=("<CLOSE_API_KEY>", ""))

print(response.json())
```

```javascript opportunities_create_example
const url = 'https://api.close.com/api/v1/opportunity/';
const credentials = btoa("<CLOSE_API_KEY>:");

const options = {
  method: 'POST',
  headers: {Authorization: `Basic ${credentials}`, 'Content-Type': 'application/json'},
  body: '{"confidence":90,"lead_id":"lead_IIDHIStmFcFQZZP0BRe99V1MCoXWz2PGCm6EDmR9v2O","note_html":"<body><p>i hope this deal closes...</p></body>","status_id":"stat_4ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk","value":500,"value_period":"monthly","custom.cf_j0P7kHmgFTZZnYBFtyPSZ3uQw4dpW8xKcW7Krps8atj":"https://www.example.com/contract.pdf"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go opportunities_create_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.close.com/api/v1/opportunity/"

	payload := strings.NewReader("{\n  \"confidence\": 90,\n  \"lead_id\": \"lead_IIDHIStmFcFQZZP0BRe99V1MCoXWz2PGCm6EDmR9v2O\",\n  \"note_html\": \"<body><p>i hope this deal closes...</p></body>\",\n  \"status_id\": \"stat_4ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk\",\n  \"value\": 500,\n  \"value_period\": \"monthly\",\n  \"custom.cf_j0P7kHmgFTZZnYBFtyPSZ3uQw4dpW8xKcW7Krps8atj\": \"https://www.example.com/contract.pdf\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.SetBasicAuth("<CLOSE_API_KEY>", "")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby opportunities_create_example
require 'uri'
require 'net/http'

url = URI("https://api.close.com/api/v1/opportunity/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.basic_auth("<CLOSE_API_KEY>", "")
request["Content-Type"] = 'application/json'
request.body = "{\n  \"confidence\": 90,\n  \"lead_id\": \"lead_IIDHIStmFcFQZZP0BRe99V1MCoXWz2PGCm6EDmR9v2O\",\n  \"note_html\": \"<body><p>i hope this deal closes...</p></body>\",\n  \"status_id\": \"stat_4ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk\",\n  \"value\": 500,\n  \"value_period\": \"monthly\",\n  \"custom.cf_j0P7kHmgFTZZnYBFtyPSZ3uQw4dpW8xKcW7Krps8atj\": \"https://www.example.com/contract.pdf\"\n}"

response = http.request(request)
puts response.read_body
```

```java opportunities_create_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.close.com/api/v1/opportunity/")
  .basicAuth("<CLOSE_API_KEY>", "")
  .header("Content-Type", "application/json")
  .body("{\n  \"confidence\": 90,\n  \"lead_id\": \"lead_IIDHIStmFcFQZZP0BRe99V1MCoXWz2PGCm6EDmR9v2O\",\n  \"note_html\": \"<body><p>i hope this deal closes...</p></body>\",\n  \"status_id\": \"stat_4ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk\",\n  \"value\": 500,\n  \"value_period\": \"monthly\",\n  \"custom.cf_j0P7kHmgFTZZnYBFtyPSZ3uQw4dpW8xKcW7Krps8atj\": \"https://www.example.com/contract.pdf\"\n}")
  .asString();
```

```php opportunities_create_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.close.com/api/v1/opportunity/', [
  'body' => '{
  "confidence": 90,
  "lead_id": "lead_IIDHIStmFcFQZZP0BRe99V1MCoXWz2PGCm6EDmR9v2O",
  "note_html": "<body><p>i hope this deal closes...</p></body>",
  "status_id": "stat_4ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk",
  "value": 500,
  "value_period": "monthly",
  "custom.cf_j0P7kHmgFTZZnYBFtyPSZ3uQw4dpW8xKcW7Krps8atj": "https://www.example.com/contract.pdf"
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
    'auth' => ['<CLOSE_API_KEY>', ''],
]);

echo $response->getBody();
```

```csharp opportunities_create_example
using RestSharp;
using RestSharp.Authenticators;

var client = new RestClient("https://api.close.com/api/v1/opportunity/");
client.Authenticator = new HttpBasicAuthenticator("<CLOSE_API_KEY>", "");
var request = new RestRequest(Method.POST);

request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"confidence\": 90,\n  \"lead_id\": \"lead_IIDHIStmFcFQZZP0BRe99V1MCoXWz2PGCm6EDmR9v2O\",\n  \"note_html\": \"<body><p>i hope this deal closes...</p></body>\",\n  \"status_id\": \"stat_4ZdiZqcSIkoGVnNOyxiEY58eTGQmFNG3LPlEVQ4V7Nk\",\n  \"value\": 500,\n  \"value_period\": \"monthly\",\n  \"custom.cf_j0P7kHmgFTZZnYBFtyPSZ3uQw4dpW8xKcW7Krps8atj\": \"https://www.example.com/contract.pdf\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```